home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap11 / howto03 / delphi10 / cciccfrm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  190.9 KB  |  5,508 lines

  1. unit Cciccfrm;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Menus, FileCtrl, CCWSock, CCICCInf,
  8.   CCICCPrf, IniFiles, Gauges , CCUUCode;
  9.  
  10. type
  11.   { This record holds the information for a number of internet connections }
  12.   PConnectionsRecord = ^TConnectionsRecord;
  13.   TConnectionsRecord = record
  14.     CProfile   : String; { Connection profile; used in lists }
  15.     CIPAddress : String; { Dotted character IP Address       }
  16.     CUserName  : String; { Login name to site; can be anonym }
  17.     CPassword  : String; { Password; won't be shown          }
  18.     CStartDir  : String; { Starting directory; used for FTP  }
  19.   end;
  20.   { Array of TCR }
  21.   CRFile = file of TConnectionsRecord; { File type for TCRec }
  22.   { This record is used to hold information about a newsgroup            }
  23.   { NOTE : hi and low pointers indicate either dl or trashing without dl }
  24.   { "read" is for an article dl'd but not trashed.                       }
  25.   PNewsGroupRecord = ^TNewsGroupRecord;
  26.   TNewsGroupRecord = record
  27.     GName                : String;  { Profile of the newsgroup              }
  28.     GRealName            : String;  { Real Newsrc name of the newsgroup     }
  29.     GLowest              : Longint; { Number of lowest dl/trashed article   }
  30.     GHighest             : Longint; { Number of highest dl/trashed article  }
  31.     GTotalNew            : Longint; { Total New articles available          }
  32.     GTotalAvailable      : Longint; { After update, shows how many arts on s}
  33.     GLowestAvailable     : Longint; { au, shows lowest a# on server         }
  34.     GHighestAvailable    : Longint; { au, shows highest a# on server        }
  35.     GPostable            : Boolean; { Can post to newsgroup                 }
  36.     GSubscribed          : Boolean; { Subscribed to newsgroup               }
  37.     GTotalArticles       : Longint; { Total articles maintained on system   }
  38.     GTotalUnReadArticles : Longint; { Total unread articles on system       }
  39.     GIDNumber            : Integer;
  40.     GFileName            : String;  { Name of file holding articles records }
  41.     GLTag                : Longint; { Tag field to hold pointer to arts TL  }
  42.   end;
  43.   NGRFile = file of TNewsGroupRecord; { File type for NGRec }
  44.   { This record is used to hold information about Newsgroup articles }
  45.   PNewsGroupArticleRecord = ^TNewsGroupArticleRecord;
  46.   TNewsGroupArticleRecord = record
  47.     NGAGroupname   : String;  { Newsgroup name (redundancy safeguard)     }
  48.     NGASubject     : String;  { Subject of article                        }
  49.     NGANumber      : Longint; { Article number                            }
  50.     NGADownloaded  : boolean; { Article attempted/succeeded downloading   }
  51.     NGASender      : String;  { Article's putative sender (CIUPKC158=us)  }
  52.     NGARead        : Boolean; { Article read flag                         }
  53.     NGAPosted      : Boolean; { Article posted flag                       }
  54.     NGAArtFileName : String;  { Name of system-gen file with article text }
  55.   end;
  56.   NGARFile = file of TNewsGroupArticleRecord;
  57.   { This record is used to hold information about EMail Mailboxes }
  58.   PEMailMailBoxRecord = ^TEMailMailBoxRecord;
  59.   TEMailMailBoxRecord = record
  60.     MBName        : String;  { Name of the mailbox                     }
  61.     MBIDNumber    : Integer;
  62.     MBMaxMsgNumber : Longint;
  63.     MBTotal       : Longint; { Total Mail Messages in Mailbox          }
  64.     MBUnReadTotal : Longint; { Total unread Mail Messages in Mailbox   }
  65.     MBUnSentTotal : Longint; { Total unsent Mail Messages in Mailbox   }
  66.     MBMsgFileName : String;  { Name of file holding Messages records   }
  67.     MBLTag        : Longint; { Tag to pointer to Tlist holding msgrecs }
  68.   end;
  69.   EMMBRFile = file of TEMailMailBoxRecord; { File type for EMMBRec }
  70.   { This record is used to hold information about EMail messages in a Mailbox }
  71.   PEMailMessageRecord = ^TEMailMessageRecord;
  72.   TEMailMessageRecord = record
  73.     MRMailBoxName      : String;  { Name of mailbox (redundancy safeguard)       }
  74.     MRMessageSubject   : String;  { Subject of the Message                       }
  75.     MRMessageRecipient : String;  { EMail address of primary recipient           }
  76.     MRMessageSender    : String;  { EMail address of sender                      }
  77.     MRCarbonCopy       : String;  { EMail CC recips; "|" delimited               }
  78.     MRBlindCarbonCopy  : String;  { EMail BCC recips; "|" delimited              }
  79.     MRDateTime         : String;  { EMail date/time field                        }
  80.     MRRead             : Boolean; { EMail Read flag                              }
  81.     MRSent             : Boolean; { EMail Send flag                              }
  82.     MRFileName         : String;  { EMail system generated filename for msg text }
  83.   end;
  84.   EMMRFile = file of TEMailMessageRecord; { File type for EMMRec }
  85.   TCCINetCCForm = class(TForm)
  86.     MainMenu1: TMainMenu;
  87.     Network1: TMenuItem;
  88.     N1: TMenuItem;
  89.     Exit1: TMenuItem;
  90.     Services1: TMenuItem;
  91.     IPAddress1: TMenuItem;
  92.     EMail1: TMenuItem;
  93.     FTP1: TMenuItem;
  94.     UsenetNws1: TMenuItem;
  95.     Panel1: TPanel;
  96.     Panel2: TPanel;
  97.     Panel3: TPanel;
  98.     Panel4: TPanel;
  99.     Panel5: TPanel;
  100.     Panel6: TPanel;
  101.     ListBox1: TListBox;
  102.     Panel7: TPanel;
  103.     SpeedButton1: TSpeedButton;
  104.     SpeedButton2: TSpeedButton;
  105.     ListBox2: TListBox;
  106.     ComboBox1: TComboBox;
  107.     Button1: TButton;
  108.     Memo1: TMemo;
  109.     Files1: TMenuItem;
  110.     Edit1: TMenuItem;
  111.     Encoding1: TMenuItem;
  112.     EMail2: TMenuItem;
  113.     FTP2: TMenuItem;
  114.     News1: TMenuItem;
  115.     Load1: TMenuItem;
  116.     Save1: TMenuItem;
  117.     Cut1: TMenuItem;
  118.     Copy1: TMenuItem;
  119.     CopytoFile1: TMenuItem;
  120.     Paste1: TMenuItem;
  121.     PastefromFile1: TMenuItem;
  122.     UUDecode1: TMenuItem;
  123.     MIMEDecode1: TMenuItem;
  124.     UUEncode1: TMenuItem;
  125.     MIMEEncode1: TMenuItem;
  126.     CheckMail1: TMenuItem;
  127.     ReplyToCurrentMessage1: TMenuItem;
  128.     SendCurrentMessage1: TMenuItem;
  129.     SendQueue1: TMenuItem;
  130.     Mailboxes1: TMenuItem;
  131.     Correspondents1: TMenuItem;
  132.     EmptyTrash1: TMenuItem;
  133.     SpeedButton4: TSpeedButton;
  134.     SpeedButton5: TSpeedButton;
  135.     SpeedButton3: TSpeedButton;
  136.     Panel8: TPanel;
  137.     Label1: TLabel;
  138.     Label2: TLabel;
  139.     ComboBox2: TComboBox;
  140.     Label3: TLabel;
  141.     ComboBox3: TComboBox;
  142.     ConnectToSite1: TMenuItem;
  143.     Disconnect1: TMenuItem;
  144.     UploadMarked1: TMenuItem;
  145.     DownloadMarked1: TMenuItem;
  146.     Directory1: TMenuItem;
  147.     ASCII1: TMenuItem;
  148.     Binary1: TMenuItem;
  149.     ASCII2: TMenuItem;
  150.     Binary2: TMenuItem;
  151.     ViewRemoteasText1: TMenuItem;
  152.     FTPSites1: TMenuItem;
  153.     CheckNewNews1: TMenuItem;
  154.     GetMarked1: TMenuItem;
  155.     CreateNewMessage1: TMenuItem;
  156.     Article1: TMenuItem;
  157.     SubscribedNewsgroups1: TMenuItem;
  158.     Trash1: TMenuItem;
  159.     Preferences1: TMenuItem;
  160.     EMail3: TMenuItem;
  161.     FTP3: TMenuItem;
  162.     News2: TMenuItem;
  163.     Label4: TLabel;
  164.     Label5: TLabel;
  165.     ViewasText1: TMenuItem;
  166.     Change1: TMenuItem;
  167.     Create1: TMenuItem;
  168.     Delete3: TMenuItem;
  169.     ChangeLocal1: TMenuItem;
  170.     OpenDialog1: TOpenDialog;
  171.     SaveDialog1: TSaveDialog;
  172.     Paths1: TMenuItem;
  173.     ProgressInfo1: TMenuItem;
  174.     N2: TMenuItem;
  175.     ViewInEditWindow1: TMenuItem;
  176.     ViewInStatusLine1: TMenuItem;
  177.     SaveToFile1: TMenuItem;
  178.     ViewWinsockInfo1: TMenuItem;
  179.     Description1: TMenuItem;
  180.     SystemStatus1: TMenuItem;
  181.     VendorSpecific1: TMenuItem;
  182.     Gauge1: TGauge;
  183.     NewsServers1: TMenuItem;
  184.     AllReadArticles1: TMenuItem;
  185.     AllMarkedArticles1: TMenuItem;
  186.     AllAvailableArticles1: TMenuItem;
  187.     NewArticle1: TMenuItem;
  188.     FollowupArticle1: TMenuItem;
  189.     Post1: TMenuItem;
  190.     CurrentArticle1: TMenuItem;
  191.     EntireQueue1: TMenuItem;
  192.     ConnectandUpdate1: TMenuItem;
  193.     Disconnect2: TMenuItem;
  194.     Headers1: TMenuItem;
  195.     RetrieveMarked1: TMenuItem;
  196.     RetrieveAll1: TMenuItem;
  197.     DownloadActiveNewsgroups1: TMenuItem;
  198.     PutinQueue1: TMenuItem;
  199.     TrashMarkedMessages1: TMenuItem;
  200.     MailServers1: TMenuItem;
  201.     ExitEMailRequired1: TMenuItem;
  202.     ToCurrentMessage1: TMenuItem;
  203.     ToNewMessage1: TMenuItem;
  204.     ToFile2: TMenuItem;
  205.     AbortNewsgroupDownload1: TMenuItem;
  206.     Catchup1: TMenuItem;
  207.     Marked1: TMenuItem;
  208.     All1: TMenuItem;
  209.     File1: TMenuItem;
  210.     SelectedArticle1: TMenuItem;
  211.     SelectMultipleArticles1: TMenuItem;
  212.     DecodeSelections1: TMenuItem;
  213.     procedure Exit1Click(Sender: TObject);
  214.     procedure FormCreate(Sender: TObject);
  215.     procedure FormDestroy(Sender: TObject);
  216.     procedure Description1Click(Sender: TObject);
  217.     procedure SystemStatus1Click(Sender: TObject);
  218.     procedure VendorSpecific1Click(Sender: TObject);
  219.     procedure ViewInEditWindow1Click(Sender: TObject);
  220.     procedure ViewInStatusLine1Click(Sender: TObject);
  221.     procedure SaveToFile1Click(Sender: TObject);
  222.     procedure IPAddress1Click(Sender: TObject);
  223.     procedure FTP1Click(Sender: TObject);
  224.     procedure FormResize(Sender: TObject);
  225.     procedure FTPSites1Click(Sender: TObject);
  226.     procedure FTP3Click(Sender: TObject);
  227.     procedure ConnectToSite1Click(Sender: TObject);
  228.     procedure Button1Click(Sender: TObject);
  229.     procedure ViewasText1Click(Sender: TObject);
  230.     procedure Disconnect1Click(Sender: TObject);
  231.     procedure ToDisplay1Click(Sender: TObject);
  232.     procedure ToFile1Click(Sender: TObject);
  233.     procedure Binary2Click(Sender: TObject);
  234.     procedure Change1Click(Sender: TObject);
  235.     procedure ChangeLocal1Click(Sender: TObject);
  236.     procedure ListBox1DblClick(Sender: TObject);
  237.     procedure ListBox2DblClick(Sender: TObject);
  238.     procedure ASCII1Click(Sender: TObject);
  239.     procedure DeleteRemoteFiles1Click(Sender: TObject);
  240.     procedure Binary1Click(Sender: TObject);
  241.     procedure Delete3Click(Sender: TObject);
  242.     procedure Create1Click(Sender: TObject);
  243.     procedure ListBox1Click(Sender: TObject);
  244.     procedure UsenetNws1Click(Sender: TObject);
  245.     procedure Disconnect2Click(Sender: TObject);
  246.     procedure News2Click(Sender: TObject);
  247.     procedure ConnectandUpdate1Click(Sender: TObject);
  248.     procedure CheckNewNews1Click(Sender: TObject);
  249.     procedure NewsServers1Click(Sender: TObject);
  250.     procedure SubscribedNewsgroups1Click(Sender: TObject);
  251.     procedure RetrieveMarked1Click(Sender: TObject);
  252.     procedure RetrieveAll1Click(Sender: TObject);
  253.     procedure GetMarked1Click(Sender: TObject);
  254.     procedure NewArticle1Click(Sender: TObject);
  255.     procedure FollowupArticle1Click(Sender: TObject);
  256.     procedure PutinQueue1Click(Sender: TObject);
  257.     procedure CurrentArticle1Click(Sender: TObject);
  258.     procedure EntireQueue1Click(Sender: TObject);
  259.     procedure AllReadArticles1Click(Sender: TObject);
  260.     procedure AllMarkedArticles1Click(Sender: TObject);
  261.     procedure AllAvailableArticles1Click(Sender: TObject);
  262.     procedure DownloadActiveNewsgroups1Click(Sender: TObject);
  263.     procedure UUEncode1Click(Sender: TObject);
  264.     procedure Load1Click(Sender: TObject);
  265.     procedure Save1Click(Sender: TObject);
  266.     procedure EMail1Click(Sender: TObject);
  267.     procedure CheckMail1Click(Sender: TObject);
  268.     procedure MailServers1Click(Sender: TObject);
  269.     procedure Mailboxes1Click(Sender: TObject);
  270.     procedure Correspondents1Click(Sender: TObject);
  271.     procedure EMail3Click(Sender: TObject);
  272.     procedure Paths1Click(Sender: TObject);
  273.     procedure ExitEMailRequired1Click(Sender: TObject);
  274.     procedure TrashMarkedMessages1Click(Sender: TObject);
  275.     procedure EmptyTrash1Click(Sender: TObject);
  276.     procedure Cut1Click(Sender: TObject);
  277.     procedure Copy1Click(Sender: TObject);
  278.     procedure CopytoFile1Click(Sender: TObject);
  279.     procedure Paste1Click(Sender: TObject);
  280.     procedure PastefromFile1Click(Sender: TObject);
  281.     procedure SpeedButton5Click(Sender: TObject);
  282.     procedure SpeedButton1Click(Sender: TObject);
  283.     procedure SpeedButton2Click(Sender: TObject);
  284.     procedure ListBox2Click(Sender: TObject);
  285.     procedure AbortNewsgroupDownload1Click(Sender: TObject);
  286.     procedure Marked1Click(Sender: TObject);
  287.     procedure All1Click(Sender: TObject);
  288.     procedure File1Click(Sender: TObject);
  289.     procedure SelectedArticle1Click(Sender: TObject);
  290.     procedure SelectMultipleArticles1Click(Sender: TObject);
  291.     procedure DecodeSelections1Click(Sender: TObject);
  292.     procedure SpeedButton4Click(Sender: TObject);
  293.   private
  294.     { Private declarations }
  295.   public
  296.     { Public declarations }
  297.     procedure EnableFTPMenus;
  298.     procedure DisableFTPMenus;
  299.     procedure EnableNNTPMenus;
  300.     procedure DisableNNTPMenus;
  301.     procedure EnablePOP3SMTPMenus;
  302.     procedure DisablePOP3SMTPMenus;
  303.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  304.     procedure UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  305.     procedure UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  306.     function DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  307.     function DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  308.     function DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  309.     procedure DoFTPDisconnect;
  310.     procedure DoNNTPDisconnect;
  311.     procedure DoPOP3SMTPDisconnect;
  312.     procedure ReadIniData;
  313.     procedure WriteIniData;
  314.     procedure LoadFTPSiteFile;
  315.     procedure LoadNNTPSiteFile;
  316.     procedure LoadEmailServerFile;
  317.     procedure SaveEMailServerFile;
  318.     procedure LoadEmailMailboxFile( WhichServer : Integer );
  319.     procedure SaveEMailMailboxFile( WhichServer : Integer );
  320.     procedure LoadEmailCorrespondentsFile;
  321.     procedure SaveEMailCorrespondentsFile;
  322.     procedure SetupEMailServerStatus;
  323.     procedure SetupNNTPServersInfoDisplay;
  324.     procedure SaveFTPSiteFile;
  325.     procedure SetupFTPSiteLists;
  326.     procedure SaveNNTPSiteFile;
  327.     procedure SetupNNTPSiteLists;
  328.     procedure SetupNNTPNewsGroupsInfoDisplay;
  329.     procedure SetupNNTPNewsGroupLists;
  330.     procedure SaveNNTPNewsGroupLists;
  331.     procedure SetupNewsGroupListboxes;
  332.     procedure SetupEMailListboxes;
  333.     procedure SetupMailboxLists;
  334.     procedure SetupEMailServersInfoDisplay;
  335.     procedure SetupEMailMailboxInfoDisplay;
  336.     procedure PopulateLB2WithArticleHeaders;
  337.     procedure PopulateLB2WithMessageHeaders;
  338.     procedure SetupEMailCorrespondentsInfoDisplay;
  339.     procedure AddNullTermTextToMemo( TheTextToAdd   : String;
  340.                                      TheMemoToAddTo : TMemo   );
  341.     function AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  342.     procedure SetHGCursors;
  343.     procedure SetNormalCursors;
  344.     procedure AddProgressText( WhatText : String );
  345.     procedure ShowProgressText( WhatText : String );
  346.     procedure ShowProgressErrorText( WhatText : String );
  347.     procedure SocketsErrorOccurred( Sender     : TObject;
  348.                                      ErrorCode  : Integer;
  349.                                      TheMessage : String   );
  350.   end;
  351.   { Component to hold FTP handling capabilities }
  352.   TFTPComponent = class( TWinControl )
  353.   public
  354.     FTPCommandInProgress ,
  355.     Connection_Established : Boolean;
  356.     Socket1 : TCCSocket;
  357.     Socket2 : TCCSocket;
  358.     constructor Create( AOwner : TComponent ); override;
  359.     destructor Destroy; override;
  360.     function GetTotalBytesToReceive( TheString : String ) : Longint;
  361.     function StripBrackets( TheString : String ) : String;
  362.     function GetShortPathname( TheString : String ) : String;
  363.     function GetWin16FileName( InputName : String ) : String;
  364.     function GetRemoteWorkingDirectory( var RemoteDir : String ) : Boolean;
  365.     function SetRemoteDirectory( TheDir : String ) : Boolean;
  366.     function DeleteRemoteDirectory( TheDir : String ) : Boolean;
  367.     function CreateRemoteDirectory( TheDir : String ) : Boolean;
  368.     function DeleteRemoteFile( TheFileName : String ) : Boolean;
  369.     function EstablishConnection( PCRPointer : PConnectionsRecord ) : Boolean;
  370.     function LoginUser( PCRPointer : PConnectionsRecord ) : Boolean;
  371.     function SendPassword( PCRPointer : PConnectionsRecord ) : Boolean;
  372.     function SetRemoteStartupDirectory( PCRPointer : PConnectionsRecord )
  373.               : Boolean;
  374.     function GetRemoteDirectoryListing( TheListBox : TListBox ) : Boolean;
  375.     function GetRemoteDirectoryListingToMemo : Boolean;
  376.     procedure SendASCIILocalFile( LocalName : String );
  377.     procedure SendBinaryLocalFile( LocalName : String );
  378.     procedure ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  379.     procedure ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  380.     function GetLocalDirectoryAndListing( var TheString : String;
  381.                                               TheListBox : TListBox )
  382.               : Boolean;
  383.     function GetUNIXTextString( var StringIn : String ) : String;
  384.     procedure ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  385.     function GetListeningPort : Integer;
  386.     procedure GetFileNameFromUNIXFileName( var TheName : String );
  387.     function Disconnect : Boolean;
  388.     function DoCStyleFormat(       TheText      : string;
  389.                              const TheArguments : array of const ) : String;
  390.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  391.     function GetQuotedString( TheString : String ) : String;
  392.     procedure AddProgressText( WhatText : String );
  393.     procedure ShowProgressText( WhatText : String );
  394.     procedure ShowProgressErrorText( WhatText : String );
  395.     function GetFTPServerResponse( var ResponseString : String ) : integer;
  396.     procedure FTPSocketsErrorOccurred( Sender     : TObject;
  397.                                      ErrorCode  : Integer;
  398.                                      TheMessage : String   );
  399.     function PerformFTPCommand(
  400.                     TheCommand   : string;
  401.               const TheArguments : array of const ) : Integer;
  402.   end;
  403. const
  404.   POV_MEMO                 = 1; { Progress to the Memo           }
  405.   POV_STAT                 = 2; { Progress to the status caption }
  406.   TCPIP_STATUS_PRELIMINARY   = 1; { Wait; command being processed  }
  407.   TCPIP_STATUS_COMPLETED     = 2; { Done; command fully succeded   }
  408.   TCPIP_STATUS_CONTINUING    = 3; { OK; send more data to finish   }
  409.   TCPIP_STATUS_RETRY_COMMAND = 4; { Temporary Error; try cmd again }
  410.   TCPIP_STATUS_FATAL_ERROR   = 5; { Fatal Error; don't retry cmd   }
  411.  
  412. var
  413.   CCINetCCForm         : TCCINetCCForm;
  414.   GlobalErrorCode      : Integer;        { Used to pass around error info  }
  415.   GlobalAbortedFlag    : Boolean;        { Used to signal timeout error    }
  416.   ProgressList         : TStringList;    { Used to hold progress text info }
  417.   ProgressFileName     : String;         { Used to hold progress file name }
  418.   ProgressOutputVector : Integer;        { Used to direct progress output  }
  419.   TheFTPSiteList       : TList;          { Used to store the FTP site recs }
  420.   TheWorkingFTPSL      : TList;          { Used to store working copy of l }
  421.   TheNewsServerList    : TList;          { Used to hold list of NNTP servs }
  422.   TheWorkingNSSL       : TList;          { Used for working copy of above  }
  423.   TheEMailServerList   : TList;          { Used for list of POP3/SMTP serv }
  424.   TheWorkingEMSL       : TList;          { Used for working copy of above  }
  425.   TheNewsRCList        : TList;          { Used for list of available ngs  }
  426.   TheWorkingNRCSL      : TList;          { Used for working copy of above  }
  427.   TheNGArticlesList    : TList;          { Used for current articles list  }
  428.                                          { (will hot swap from pointer of  }
  429.                                          {  Tlist of Tlists in base rec.)  }
  430.   TheEMailMailboxList  : TList;          { Used for list of available mbs  }
  431.   TheWorkingMBSL       : TList;          { Used for working copy of above  }
  432.   TheCorrespondentsList: TList;          { Used for list of correspondents }
  433.   TheWorkingCPSL       : TList;          { Used for working copy of above  }
  434.   TheMBMessagesList    : TList;          { Used for current msgs; hotswaps }
  435.   TheEMailServerFile   : CRFile;         { File of Email servers records   }
  436.   TheEMailCorrespondentsFile : CRFile;
  437.   TheNewsServerFile    : CRFile;         { File of NNTP servers records    }
  438.   TheNewsRCFile        : NGRFile;        { File of Newsgroups records      }
  439.   TheNewsArticleFile   : NGARFile;       { Current ng articles records file}
  440.   TheEMailMailboxFile  : EMMBRFile;      { File of Mailboxes records       }
  441.   TheEMailMessagesFile : EMMRFile;       { Current mb messages records file}
  442.   TheFTPSiteFile       : CRFile;         { Used to load the FTP site file  }
  443.   TheICCIniFile        : TIniFile;       { Used to retrieve the INI File   }
  444.   MailPath             : String;         { Used for path to Mail Files     }
  445.   NewsPath             : String;         { Used for path to News Files     }
  446.   FTPPath              : String;         { Used for path to FTP Files      }
  447.   CurrentPassWordString : String;        { Used to hold login id for anons }
  448.   CurrentEMPassWordString : String;      { Used to hold login id for anons }
  449.   PassWordControlVector : Integer;       { Used to hold display of pw vect }
  450.   CurrentRealPWString   : String;        { Used to hold a real password    }
  451.   EMPassWordControlVector : Integer;       { Used to hold display of pw vect }
  452.   CurrentEMRealPWString   : String;        { Used to hold a real password    }
  453.   TheFTPComponent       : TFTPComponent; { FTP Object                      }
  454.   TheLine ,
  455.   HolderLine ,
  456.   GlobalTextBuffer      : String;
  457.   TheAnonRedialVector ,
  458.   DefaultDownloadVector : Integer;
  459.   NewsReadArticlePurgingVector : Integer;
  460.   NewsPostQueueingVector : Integer;
  461.   NewsReadArticleDisplayVector : Integer;
  462.   NewsUUMIMEVector : Integer;
  463.   NewsInitialUpdateVector : Integer;
  464.   LeftoverText          : String;
  465.   LeftoversOnTable      : Boolean;
  466.   FileNameToXFer        : String;
  467.   WhichServer           : Integer;       { Holds current NNTP server }
  468.   WhichGroup            : Integer;       { Holds current NNTP newsgroup }
  469.   TheUUObject           : TUUCodingObject;
  470.   EMRemoteDeletionVector : Integer;
  471.   EMChokeVector : Integer;
  472.   EMDefaultDownloadVector : Integer;
  473.   EMQueueVector : Integer;
  474.   NewsgroupListLoaded ,
  475.   EmailLoaded ,
  476.   NewMessageInProgress : Boolean;
  477.   TheUUDecodeList      : TStringList;
  478.   
  479. implementation
  480.  
  481. uses CCICCPOP, CCICNNTP;
  482.  
  483. var
  484.   TheNNTPComponent      : TNNTPComponent;{ NNTP News Object                }
  485.  
  486. {$R *.DFM}
  487.  
  488.  
  489. { This procedure actually attempts to connect to the internet at an POP3SMTP site }
  490. function TCCINetCCForm.DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  491. begin
  492.   { Create the component }
  493.   Result := false;
  494.   { Do busy cursors }
  495.   SetHGCursors;
  496.   if not ThePOP3SMTPComponent.EstablishPOP3Connection( PCRPointer ) then
  497.   begin
  498.     { Do saved cursors }
  499.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  500.     ThePOP3SMTPComponent.Connection_Established := false;
  501.     SetNormalCursors;
  502.     exit;
  503.   end;
  504.   if not ThePOP3SMTPComponent.LoginUser( PCRPointer ) then
  505.   begin
  506.     { Do saved cursors }
  507.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  508.     ThePOP3SMTPComponent.Connection_Established := false;
  509.     SetNormalCursors;
  510.     exit;
  511.   end;
  512.   if not ThePOP3SMTPComponent.SendPassword( PCRPointer ) then
  513.   begin
  514.     { Do saved cursors }
  515.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  516.     ThePOP3SMTPComponent.Connection_Established := false;
  517.     SetNormalCursors;
  518.     exit;
  519.   end;
  520.   SetNormalCursors;
  521.   Result := true;
  522.   EnablePOP3SMTPMenus;
  523.   ThePOP3SMTPComponent.POP3CommandInProgress := false;
  524.   Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  525. end;
  526.  
  527. { This procedure actually attempts to disconnect to the internet at an ftp site}
  528. procedure TCCINetCCForm.DoPOP3SMTPDisconnect;
  529. begin
  530.   { Kill the socket }
  531.   ThePOP3SMTPComponent.Socket1.CCSockClose;
  532.   ThePOP3SMTPComponent.Connection_Established := false;
  533. end;
  534.  
  535. { Procedure to load the POP3SMTP Site list }
  536. procedure TCCINetCCForm.LoadEmailServerFile;
  537. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  538.     PSSLName     : String;             { POP3SMTP Site List filename }
  539.     Counter_1    : Integer;            { Loop counter           }
  540. begin
  541.   { Create the sites list list }
  542.   TheEMailServerList := TList.Create;
  543.   { Set up the FTP sites list file name }
  544.   PSSLName := MailPath + '\PSSERVER.TCR';
  545.   { If the FTP Site List exists load it in }
  546.   if FileExists( PSSLName ) then
  547.   begin
  548.     { set up the file and open it }
  549.     AssignFile( TheEMailServerFile , PSSLName );
  550.     Reset( TheEMailServerFile );
  551.     { read in the records }
  552.     for Counter_1 := 0 to FileSize( TheEMailServerFile ) - 1 do
  553.     begin
  554.       { Create the TCRecord }
  555.       New( ThePSSRecord );
  556.       { Read in the data record }
  557.       Seek( TheEMailServerFile , Counter_1 );
  558.       Read( TheEMailServerFile , ThePSSRecord^ );
  559.       { Add the record to the list }
  560.       TheEMailServerList.Add( ThePSSRecord );
  561.     end;
  562.     { close the file }
  563.     CloseFile( TheEMailServerFile );
  564.   end
  565.   else
  566.   { Otherwise create a default one with the a generic mail site (?) }
  567.   begin
  568.     { create new record }
  569.     New( ThePSSRecord );
  570.     { fill in its info }
  571.     with ThePSSRecord^ do
  572.     begin
  573.       CProfile   := 'My Mail Server';
  574.       CIPAddress := 'mail.myprovider.com';
  575.       CUserName  := 'myname';
  576.       CPassword  := 'mypassword';
  577.       CStartDir  := 'myname@myprovider.com';
  578.     end;
  579.     { add it to the list }
  580.     { do it three more times }
  581.     TheEMailServerList.Add( ThePSSRecord );
  582.     { create the file and write out the data, then close it }
  583.     AssignFile( TheEMailServerFile , PSSLName );
  584.     Rewrite( TheEMailServerFile );
  585.     ThePSSRecord :=
  586.        PConnectionsRecord( TheEMailServerList.Items[ 0 ] );
  587.       Seek( TheEMailServerFile , 0 );
  588.       Write( TheEMailServerFile , ThePSSRecord^ );
  589.     CloseFile( TheEMailServerFile );
  590.   end;
  591.   TheWorkingEMSL := TList.Create;
  592.   For Counter_1 := 0 to TheEMailServerList.Count - 1 do
  593.   begin
  594.     New( ThePSSRecord );
  595.     ThePSSRecord^ := PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] )^;
  596.     TheWorkingEMSL.Add( ThePSSRecord );
  597.   end;
  598. end;
  599.  
  600. procedure TCCINetCCForm.SaveEMailServerFile;
  601. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  602.     PSSLName     : String;             { POP3SMTP Site List filename }
  603.     Counter_1    : Integer;            { Loop counter           }
  604. begin
  605.   { Set up the file name }
  606.   PSSLName := MailPath + '\PSSERVER.TCR';
  607.   { Assign the file }
  608.   AssignFile( TheEMailServerFile , PSSLName );
  609.   { Rewrite it }
  610.   Rewrite( TheEMailServerFile );
  611.   { run the list through the procedure }
  612.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  613.   begin
  614.     { get the record from the list }
  615.     ThePSSRecord :=
  616.      PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] );
  617.     { Do the seek/write }
  618.     Seek( TheEMailServerFile , Counter_1 );
  619.     Write( TheEMailServerFile , ThePSSRecord^ );
  620.     { free the record }
  621.     Dispose( ThePSSRecord );
  622.   end;
  623.   { Close the file }
  624.   CloseFile( TheEMailServerFile );
  625.   { Free the list pointers }
  626.   TheEMailServerList.Free;
  627.   for Counter_1 := 0 to TheWorkingEMSL.Count - 1 do
  628.   begin
  629.     ThePSSRecord := PConnectionsRecord( TheWorkingEMSL.Items[ Counter_1 ] );
  630.     Dispose( ThePSSRecord );
  631.   end;
  632.   TheWorkingEMSL.Free;
  633. end;
  634.  
  635. { Procedure to load the POP3SMTP Site list }
  636. procedure TCCINetCCForm.LoadEmailMailboxFile( WhichServer : Integer );
  637. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  638.     PSMBName    : String;              { Mailbox filename       }
  639.     Counter_1   ,
  640.     Counter_2   : Integer;             { Loop counter           }
  641.     TheMessagesList : TList;
  642.     TheEMMRecord : PEMailMessageRecord;
  643. begin
  644.   { Create the sites list list }
  645.   TheEMailMailboxList := TList.Create;
  646.   { Set up the FTP sites list file name }
  647.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  648.   { If the FTP Site List exists load it in }
  649.   if FileExists( PSMBName ) then
  650.   begin
  651.     { set up the file and open it }
  652.     AssignFile( TheEMailMailboxFile , PSMBName );
  653.     Reset( TheEMailMailboxFile );
  654.     { read in the records }
  655.     for Counter_1 := 0 to FileSize( TheEMailMailboxFile ) - 1 do
  656.     begin
  657.       { Create the TCRecord }
  658.       New( TheMBRecord );
  659.       { Read in the data record }
  660.       Seek( TheEMailMailboxFile , Counter_1 );
  661.       Read( TheEMailMailboxFile , TheMBRecord^ );
  662.       { Add the record to the list }
  663.       TheEMailMailboxList.Add( TheMBRecord );
  664.     end;
  665.     { close the file }
  666.     CloseFile( TheEMailMailboxFile );
  667.   end
  668.   else
  669.   { Otherwise create a default one with the In and Out mailboxes (?) }
  670.   begin
  671.     { create new record }
  672.     New( TheMBRecord );
  673.     { fill in its info }
  674.     with TheMBRecord^ do
  675.     begin
  676.       MBName         := 'In Box';
  677.       MBIDNumber     := 1;
  678.       MBMaxMsgNumber := 0;
  679.       MBTotal        := 0;
  680.       MBUnReadTotal  := 0;
  681.       MBUnSentTotal  := 0;
  682.       MBMsgFileName  := 'MB1.MBX';
  683.       MBLTag         := 0;
  684.     end;
  685.     { add it to the list }
  686.     TheEMailMailboxList.Add( TheMBRecord );
  687.     { create new record }
  688.     New( TheMBRecord );
  689.     { fill in its info }
  690.     with TheMBRecord^ do
  691.     begin
  692.       MBName         := 'Out Box';
  693.       MBIDNumber     := 2;
  694.       MBMaxMsgNumber := 0;
  695.       MBTotal        := 0;
  696.       MBUnReadTotal  := 0;
  697.       MBUnSentTotal  := 0;
  698.       MBMsgFileName  := 'MB2.MBX';
  699.       MBLTag         := 0;
  700.     end;
  701.     { add it to the list }
  702.     TheEMailMailboxList.Add( TheMBRecord );
  703.     { create the file and write out the data, then close it }
  704.     AssignFile( TheEMailMailboxFile , PSMBName );
  705.     Rewrite( TheEMailMailboxFile );
  706.     TheMBRecord :=
  707.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  708.       Seek( TheEMailMailboxFile , 0 );
  709.       Write( TheEMailMailboxFile , TheMBRecord^ );
  710.     TheMBRecord :=
  711.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 1 ] );
  712.       Seek( TheEMailMailboxFile , 1 );
  713.       Write( TheEMailMailboxFile , TheMBRecord^ );
  714.     CloseFile( TheEMailMailboxFile );
  715.   end;
  716.   { Load in Message Records and create storage lists }
  717.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  718.   begin
  719.     PSMBName := PEMailMailboxRecord(
  720.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  721.     if FileExists( MailPath + '\' + PSMBName ) then
  722.     begin
  723.       TheMessagesList := TList.Create;
  724.       AssignFile( TheEMailMessagesFile , MailPath + '\' + PSMBName );
  725.       Reset( TheEMailMessagesFile );
  726.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  727.       begin
  728.         New( TheEMMRecord );
  729.         Seek( TheEMailMessagesFile , Counter_2 );
  730.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  731.         TheMessagesList.Add( TheEMMRecord );
  732.       end;
  733.       CloseFile( TheEMailMessagesFile );
  734.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  735.        Longint( TheMessagesList );
  736.     end
  737.     else
  738.     begin
  739.       TheMessagesList := TList.Create;
  740.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  741.        Longint( TheMessagesList );
  742.     end;
  743.   end;
  744.   TheWorkingMBSL := TList.Create;
  745.   For Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  746.   begin
  747.     New( TheMBRecord );
  748.     TheMBRecord^ := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^;
  749.     TheWorkingMBSL.Add( TheMBRecord );
  750.   end;
  751. end;
  752.  
  753. procedure TCCINetCCForm.SaveEMailMailboxFile( WhichServer : Integer );
  754. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  755.     PSMBName    : String;              { Mailbox filename       }
  756.     Counter_2 ,
  757.     Counter_1   : Integer;             { Loop counter           }
  758.     TheList     : TList;
  759.     TheEMMRecord : PEMailMessageRecord;
  760. begin
  761.   { Load in Message Records and create storage lists }
  762.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  763.   begin
  764.     PSMBName := PEMailMailboxRecord(
  765.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  766.     TheList := TList( PEMailMailboxRecord(
  767.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag );
  768.     AssignFile( TheEMailMessagesFile , Mailpath + '\' + PSMBName );
  769.     Rewrite( TheEMailMessagesFile );
  770.     for Counter_2 := 0 to TheList.Count - 1 do
  771.     begin
  772.       TheEMMRecord := PEMailMessageRecord( TheList.Items[ Counter_2 ] );
  773.       Seek( TheEMailMessagesFile , Counter_2 );
  774.       Write( TheEMailMessagesFile , TheEMMRecord^ );
  775.       Dispose( TheEMMRecord );
  776.     end;
  777.     CloseFile( TheEMailMessagesFile );
  778.     TheList.Free;
  779.   end;
  780.   { Set up the file name }
  781.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  782.   { Assign the file }
  783.   AssignFile( TheEMailMailboxFile , PSMBName );
  784.   { Rewrite it }
  785.   Rewrite( TheEMailMailboxFile );
  786.   { run the list through the procedure }
  787.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  788.   begin
  789.     { get the record from the list }
  790.     TheMBRecord :=
  791.      PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  792.     { Do the seek/write }
  793.     Seek( TheEMailMailboxFile , Counter_1 );
  794.     Write( TheEMailMailboxFile , TheMBRecord^ );
  795.     { free the record }
  796.     Dispose( TheMBRecord );
  797.   end;
  798.   { Close the file }
  799.   CloseFile( TheEMailMailboxFile );
  800.   { Free the list pointers }
  801.   TheEMailMailboxList.Free;
  802.   for Counter_1 := 0 to TheWorkingMBSL.Count - 1 do
  803.   begin
  804.     TheMBRecord := PEMailMailboxRecord( TheWorkingMBSL.Items[ Counter_1 ] );
  805.     Dispose( TheMBRecord );
  806.   end;
  807.   TheWorkingMBSL.Free;
  808. end;
  809.  
  810. { Procedure to load the POP3SMTP Site list }
  811. procedure TCCINetCCForm.LoadEmailCorrespondentsFile;
  812. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  813.     PSSLName     : String;             { POP3SMTP Site List filename }
  814.     Counter_1    : Integer;            { Loop counter           }
  815. begin
  816.   { Create the sites list list }
  817.   TheCorrespondentsList := TList.Create;
  818.   { Set up the FTP sites list file name }
  819.   PSSLName := MailPath + '\PSCORRSP.TCR';
  820.   { If the FTP Site List exists load it in }
  821.   if FileExists( PSSLName ) then
  822.   begin
  823.     { set up the file and open it }
  824.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  825.     Reset( TheEMailCorrespondentsFile );
  826.     { read in the records }
  827.     for Counter_1 := 0 to FileSize( TheEMailCorrespondentsFile ) - 1 do
  828.     begin
  829.       { Create the TCRecord }
  830.       New( ThePSSRecord );
  831.       { Read in the data record }
  832.       Seek( TheEMailCorrespondentsFile , Counter_1 );
  833.       Read( TheEMailCorrespondentsFile , ThePSSRecord^ );
  834.       { Add the record to the list }
  835.       TheCorrespondentsList.Add( ThePSSRecord );
  836.     end;
  837.     { close the file }
  838.     CloseFile( TheEMailCorrespondentsFile );
  839.   end
  840.   else
  841.   { Otherwise create a default one with the author }
  842.   begin
  843.     { create new record }
  844.     New( ThePSSRecord );
  845.     { fill in its info }
  846.     with ThePSSRecord^ do
  847.     begin
  848.       CProfile   := 'Nathan Wallace at TDE';
  849.       CIPAddress := 'kilgalen@tde.com';
  850.       CUserName  := '';
  851.       CPassword  := '';
  852.       CStartDir  := '';
  853.     end;
  854.     { add it to the list }
  855.     { do it three more times }
  856.     TheCorrespondentsList.Add( ThePSSRecord );
  857.     { create the file and write out the data, then close it }
  858.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  859.     Rewrite( TheEMailCorrespondentsFile );
  860.     ThePSSRecord :=
  861.        PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] );
  862.       Seek( TheEMailCorrespondentsFile , 0 );
  863.       Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  864.     CloseFile( TheEMailCorrespondentsFile );
  865.   end;
  866.   TheWorkingCPSL := TList.Create;
  867.   For Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  868.   begin
  869.     New( ThePSSRecord );
  870.     ThePSSRecord^ := PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] )^;
  871.     TheWorkingCPSL.Add( ThePSSRecord );
  872.   end;
  873.   CCInetCCForm.ComboBox2.Clear;
  874.   CCInetCCForm.ComboBox3.Clear;
  875.   { Add the new info }
  876.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  877.   begin
  878.     CCINetCCForm.ComboBox2.Items.Add( PConnectionsRecord(
  879.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  880.     CCINetCCForm.ComboBox3.Items.Add( PConnectionsRecord(
  881.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  882.   end;
  883.   CCINetCCForm.ComboBox2.ItemIndex := 0;
  884.   CCINetCCForm.ComboBox3.ItemIndex := 0;
  885. end;
  886.  
  887. procedure TCCINetCCForm.SaveEMailCorrespondentsFile;
  888. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  889.     PSSLName     : String;             { POP3SMTP Site List filename }
  890.     Counter_1    : Integer;            { Loop counter           }
  891. begin
  892.   { Set up the file name }
  893.   PSSLName := MailPath + '\PSCORRSP.TCR';
  894.   { Assign the file }
  895.   AssignFile( TheEMailCorrespondentsFile , PSSLName );
  896.   { Rewrite it }
  897.   Rewrite( TheEMailCorrespondentsFile );
  898.   { run the list through the procedure }
  899.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  900.   begin
  901.     { get the record from the list }
  902.     ThePSSRecord :=
  903.      PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] );
  904.     { Do the seek/write }
  905.     Seek( TheEMailCorrespondentsFile , Counter_1 );
  906.     Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  907.     { free the record }
  908.     Dispose( ThePSSRecord );
  909.   end;
  910.   { Close the file }
  911.   CloseFile( TheEMailCorrespondentsFile );
  912.   { Free the list pointers }
  913.   TheCorrespondentsList.Free;
  914.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  915.   begin
  916.     ThePSSRecord := PConnectionsRecord( TheWorkingCPSL.Items[ Counter_1 ] );
  917.     Dispose( ThePSSRecord );
  918.   end;
  919.   TheWorkingCPSL.Free;
  920. end;
  921.  
  922. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  923. procedure TCCINetCCForm.SetupEMailServerStatus;
  924. begin
  925.   { Set up display for main form }
  926.   CCINetCCForm.Tag := 6; { Email Tag }
  927.   CCINetCCForm.Caption := 'CC Internet Command Center -- EMail Mode';
  928.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  929.   CCINetCCForm.EMail2.Enabled := true;
  930.   CCINetCCForm.EMail1.Enabled := false;
  931.   CCINetCCForm.UsenetNws1.Enabled := false;
  932.   CCINetCCForm.FTP1.Enabled := false;
  933.   CCINetCCForm.Label1.Caption := 'Mail Server:';
  934.   CCINetCCForm.Button1.Caption := 'New Mail';
  935.   CCINetCCForm.Label4.Caption := 'Mailboxes';
  936.   CCINetCCForm.Label5.Caption := 'Messages';
  937. end;
  938.  
  939. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  940. procedure TCCINetCCForm.SetupMailboxLists;
  941. var TheEMMRecord : PEMailMessageRecord; {  }
  942.     Counter_1 ,
  943.     Counter_2    : Integer;             {  }
  944.     EMMFileName  : String;              {  }
  945.     WorkingList  : TList;
  946. begin
  947.   { Abort if no server to select }
  948.   if ComboBox1.ItemIndex = -1 then exit;
  949.   { Get number of server in list }
  950.   WhichServer := ComboBox1.ItemIndex;
  951.   { Load in mailbox data }
  952.   LoadEmailMailboxFile( WhichServer );
  953.   { Load in Mailbox Records and create storage lists }
  954.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  955.   begin
  956.     EMMFileName := PEMailMailboxRecord(
  957.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  958.     if FileExists( MailPath + '\' + EMMFileName ) then
  959.     begin
  960.       WorkingList := TList.Create;
  961.       AssignFile( TheEMailMessagesFile , EMMFileName );
  962.       Reset( TheEMailMessagesFile );
  963.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  964.       begin
  965.         New( TheEMMRecord );
  966.         Seek( TheEMailMessagesFile , Counter_2 );
  967.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  968.         WorkingList.Add( TheEMMRecord );
  969.       end;
  970.       CloseFile( TheEMailMessagesFile );
  971.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  972.        Longint( WorkingList );
  973.     end
  974.     else
  975.     begin
  976.       WorkingList := TList.Create;
  977.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  978.        Longint( WorkingList );
  979.     end;
  980.   end;
  981. end;
  982.  
  983. { This procedure populates LB2 with article subjects for any }
  984. { available articles for a given newsgroup.                  }
  985. procedure TCCINetCCForm.PopulateLB2WithMessageHeaders;
  986. var Counter_1    : Integer;
  987.     TheEMMRecord : PEMailMessageRecord;
  988.     TempString   : String;
  989. begin
  990.   { Clear target list box }
  991.   ListBox2.Clear;
  992.   for Counter_1 := 0 to TheMBMessagesList.Count - 1 do
  993.   begin
  994.     TheEMMRecord :=
  995.      PEMailMessageRecord( TheMBMessagesList.Items[ Counter_1 ] );
  996.     TempString := '    [' + IntToStr( Counter_1 + 1 ) + '] ' +
  997.      TheEMMRecord^.MRMessageSubject;
  998.     if TheEMMRecord^.MRRead then TempString[ 2 ] := 'R';
  999.     if TheEMMRecord^.MRSent then TempString[ 2 ] := 'S';
  1000.     if TheEMMRecord^.MRMessageSender = 'DELETE ME' then TempString[ 3 ] := 'T';
  1001.     ListBox2.Items.Add( TempString );
  1002.   end;
  1003. end;
  1004.  
  1005. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  1006. { and calls another procedure to populate LB2 with any available   }
  1007. { articles for the newsgroup.                                      }
  1008. procedure TCCINetCCForm.SetupEMailListboxes;
  1009. var Counter_1   : Integer;
  1010.     TempString  : String;
  1011.     TheMBRecord : PEMailMailboxRecord;
  1012. begin
  1013.   ListBox1.Clear;
  1014.   ListBox1.Tag := 6;
  1015.   ListBox2.Tag := 6;
  1016.   Label4.Caption := 'Mailboxes';
  1017.   Label5.Caption := 'Messages';
  1018.   if TheEMailMailboxList.Count = 0 then
  1019.   begin
  1020.     ListBox2.Clear;
  1021.     exit;
  1022.   end;
  1023.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1024.   begin
  1025.     TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  1026.     TempString := TheMBRecord^.MBName;
  1027.     if TheMBRecord^.MBUnSentTotal > 0 then TempString := TempString + ' {' +
  1028.      IntToStr( TheMBRecord^.MBUnSentTotal ) + ' Queued}' else
  1029.      if TheMBRecord^.MBUnReadTotal > 0 then TempString := TempString +
  1030.        ' {' + IntToStr( TheMBRecord^.MBUnReadTotal ) + ' New}';
  1031.     TempString := TempString + '{' + IntToStr( TheMBRecord^.MBTotal ) + ' Stored}';
  1032.     ListBox1.Items.Add( TempString );
  1033.   end;
  1034.   TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  1035.   TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  1036.   PopulateLB2WithMessageHeaders;
  1037.   Label1.Caption := 'MailBox:';
  1038.   Button1.Caption := 'New Mail';
  1039. end;
  1040.  
  1041. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1042. procedure TCCINetCCForm.SetupEMailServersInfoDisplay;
  1043. var Counter_1  : Integer;            { Loop counter        }
  1044. begin
  1045.   { Set tag for POP3SMTP stuff }
  1046.   CCICInfoDlg.Tag := 6; { EMail Tag -- servers }
  1047.   { set up caption of main label }
  1048.   CCICInfoDlg.Label2.Caption := 'EMail Server Sites';
  1049.   { hide outline panel }
  1050.   CCICInfoDlg.Panel6.Top := 200;
  1051.   CCICInfoDlg.panel6.Height := 144;
  1052.   CCICInfoDlg.Panel6.Visible := false;
  1053.   CCICInfoDlg.Panel5.Visible := true;
  1054.   CCICInfoDlg.Panel8.Visible := true;
  1055.   CCICInfoDlg.Panel9.Visible := true;
  1056.   { clear the list box }
  1057.   CCICInfoDlg.ListBox1.Visible := false;
  1058.   CCICInfoDlg.ListBox2.Clear;
  1059.   CCINetCCForm.ComboBox1.Clear;
  1060.   { add profile strings to the list box }
  1061.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  1062.   begin
  1063.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1064.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1065.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  1066.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1067.   end;
  1068.   { Set up caption of special button }
  1069.   CCICInfoDlg.Button1.Visible := false;
  1070.   { Start with top record }
  1071.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1072.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  1073.   { put in data from top record and reset captions }
  1074.   with PConnectionsRecord( TheEMailServerList.Items[ 0 ] )^ do
  1075.   begin
  1076.     with CCICInfoDlg do
  1077.     begin
  1078.       Edit1.Text := CProfile;
  1079.       Panel2.Caption := '            Name:';
  1080.       Edit2.Text := CIPAddress;
  1081.       Panel3.Caption := '     IP Address:';
  1082.       Edit3.Text := CUserName;
  1083.       Panel5.Caption := '    User Name:';
  1084.       CurrentEMRealPWString := CPassword;
  1085.       case EMPasswordControlVector of
  1086.         1 : Edit4.Text := CPassword;
  1087.         2 : Edit4.Text := '**********';
  1088.       end;
  1089.       Panel8.Caption := '      Password:';
  1090.       Edit5.Text := CStartDir;
  1091.       Panel9.Caption := '    EMail Address:';
  1092.     end;
  1093.   end;
  1094. end;
  1095.  
  1096. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1097. procedure TCCINetCCForm.SetupEMailMailboxInfoDisplay;
  1098. var Counter_1      : Integer;
  1099.     TheWorkingList : TList;
  1100. begin
  1101.   { Set tag for POP3SMTP stuff }
  1102.   CCICInfoDlg.Tag := 7; { EMail Tag -- mailboxes }
  1103.   { set up caption of main label }
  1104.   CCICInfoDlg.Label2.Caption := 'Mailboxes';
  1105.   { hide outline panel }
  1106.   CCICInfoDlg.Panel6.Visible := true;
  1107.   CCICInfoDlg.Panel6.Top := 40;
  1108.   CCICInfoDlg.Panel6.Height := 304;
  1109.   CCICInfoDlg.Label1.Caption := 'Saved Messages';
  1110.   CCICInfoDlg.Panel3.Visible := false;
  1111.   CCICInfoDlg.Panel5.Visible := false;
  1112.   CCICInfoDlg.Panel8.Visible := false;
  1113.   CCICInfoDlg.Panel9.Visible := false;
  1114.   { clear the list box }
  1115.   CCICInfoDlg.ListBox1.Visible := true;
  1116.   CCICInfoDlg.ListBox1.MultiSelect := true;
  1117.   CCICInfoDlg.ListBox1.ExtendedSelect := true;
  1118.   CCICInfoDlg.ListBox2.Clear;
  1119.   CCICInfoDlg.ListBox1.Clear;
  1120.   { add profile strings to the list box }
  1121.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1122.   begin
  1123.     CCICInfoDlg.ListBox2.Items.Add( PEMailMailboxRecord(
  1124.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBName );
  1125.   end;
  1126.   { Set up caption of special button }
  1127.   CCICInfoDlg.Button1.Visible := true;
  1128.   CCICInfoDlg.Button1.Caption := 'XFer on Click';
  1129.   { Start with top record }
  1130.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1131.   { put in data from top record and reset captions }
  1132.   with PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] )^ do
  1133.   begin
  1134.     with CCICInfoDlg do
  1135.     begin
  1136.       Edit1.Text := MBName;
  1137.       Panel2.Caption := 'MB Name:';
  1138.       TheWorkingList := TList( MBLTag );
  1139.       if TheWorkingList.Count > 0 then
  1140.       begin
  1141.         ListBox1.Clear;
  1142.         for Counter_1 := 0 to TheWorkingList.Count - 1 do
  1143.         begin
  1144.           ListBox1.Items.Add( PEMailMessageRecord(
  1145.            TheWorkingList.Items[ Counter_1 ] )^.MRMessageSubject );
  1146.         end;
  1147.         Listbox1.ItemIndex := 0;
  1148.       end;
  1149.     end;
  1150.   end;
  1151. end;
  1152.  
  1153. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1154. procedure TCCINetCCForm.SetupEMailCorrespondentsInfoDisplay;
  1155. var Counter_1  : Integer;            { Loop counter        }
  1156. begin
  1157.   { Set tag for POP3SMTP stuff }
  1158.   CCICInfoDlg.Tag := 8; { EMail Tag -- correspondents }
  1159.   { set up caption of main label }
  1160.   CCICInfoDlg.Label2.Caption := 'Correspondents';
  1161.   { hide outline panel }
  1162.   CCICInfoDlg.Panel3.Visible := true;
  1163.   CCICInfoDlg.Panel6.Visible := false;
  1164.   CCICInfoDlg.Panel5.Visible := false;
  1165.   CCICInfoDlg.Panel8.Visible := false;
  1166.   CCICInfoDlg.Panel9.Visible := false;
  1167.   CCICInfoDlg.ListBox1.Visible := false;
  1168.   { clear the list box }
  1169.   CCICInfoDlg.ListBox2.Clear;
  1170.   { add profile strings to the list box }
  1171.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  1172.   begin
  1173.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1174.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  1175.   end;
  1176.   { Set up caption of special button }
  1177.   CCICInfoDlg.Button1.Visible := false;
  1178.   { Start with top record }
  1179.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1180.   { put in data from top record and reset captions }
  1181.   with PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] )^ do
  1182.   begin
  1183.     with CCICInfoDlg do
  1184.     begin
  1185.       Edit1.Text := CProfile;
  1186.       Panel2.Caption := '            Name:';
  1187.       Edit2.Text := CIPAddress;
  1188.       Panel3.Caption := 'EMail Address:';
  1189.     end;
  1190.   end;
  1191. end;
  1192.  
  1193. procedure TCCINetCCForm.EnablePOP3SMTPMenus;
  1194. begin
  1195.   Button1.Caption := 'New Mail';
  1196.   CheckMail1.Enabled := true;
  1197.   CreateNewMessage1.Enabled := true;
  1198.   ReplyToCurrentMessage1.Enabled := true;
  1199.   SendCurrentMessage1.Enabled := true;
  1200.   SendQueue1.Enabled := true;
  1201.   MailServers1.Enabled := true;
  1202.   MailBoxes1.Enabled := true;
  1203.   Correspondents1.Enabled := true;
  1204.   TrashMarkedMessages1.Enabled := true;
  1205.   EmptyTrash1.Enabled := true;
  1206. end;
  1207.  
  1208. procedure TCCINetCCForm.DisablePOP3SMTPMenus;
  1209. begin
  1210.   CheckMail1.Enabled := False;
  1211.   CreateNewMessage1.Enabled := False;
  1212.   ReplyToCurrentMessage1.Enabled := False;
  1213.   SendCurrentMessage1.Enabled := False;
  1214.   SendQueue1.Enabled := False;
  1215.   MailServers1.Enabled := False;
  1216.   MailBoxes1.Enabled := False;
  1217.   Correspondents1.Enabled := False;
  1218.   TrashMarkedMessages1.Enabled := False;
  1219.   EmptyTrash1.Enabled := False;
  1220.   EMail1.Enabled := true;
  1221.   FTP1.Enabled := true;
  1222.   UseNetNws1.Enabled := true;
  1223.   IPAddress1.Enabled := true;
  1224.   EMail2.Enabled := false;
  1225. end;
  1226.  
  1227. { This is the FTP component constructor; it creates 2 sockets }
  1228. constructor TFTPComponent.Create( AOwner : TComponent );
  1229. begin
  1230.   { do inherited create }
  1231.   inherited Create( AOwner );
  1232.   { Create sockets, put in their parents, and error procs }
  1233.   Socket1 := TCCSocket.Create( Self );
  1234.   Socket1.Parent := Self;
  1235.   Socket1.OnErrorOccurred := FTPSocketsErrorOccurred;
  1236.   Socket2 := TCCSocket.Create( Self );
  1237.   Socket2.Parent := Self;
  1238.   Socket2.OnErrorOccurred := FTPSocketsErrorOccurred;
  1239.   { Set up booleans }
  1240.   Connection_Established := false;
  1241.   FTPCommandInProgress := false;
  1242. end;
  1243.  
  1244. { This is the FTP component destructor; it frees 2 sockets }
  1245. destructor TFTPComponent.Destroy;
  1246. begin
  1247.   { Free the sockets }
  1248.   Socket1.Free;
  1249.   Socket2.Free;
  1250.   { and call inherited }
  1251.   inherited Destroy;
  1252. end;
  1253.  
  1254. function TFTPComponent.GetShortPathname( TheString : String ) : String;
  1255. var HoldingString : String;
  1256. begin
  1257.   HoldingString := Copy( TheString , 1 , 3 );
  1258.   HoldingString := HoldingString + '..\' + ExtractFileName( TheString );
  1259.   Result := HoldingString;
  1260. end;
  1261.  
  1262. function TFTPComponent.StripBrackets( TheString : String ) : String;
  1263. var HoldingString : String;
  1264.     HoldingPosition : Integer;
  1265. begin
  1266.   HoldingPosition := Pos( '[' , TheString );
  1267.   if HoldingPosition = 0 then
  1268.   begin
  1269.     Result := TheString;
  1270.     exit;
  1271.   end
  1272.   else
  1273.   begin
  1274.     HoldingString := Copy( TheString , HoldingPosition + 1 , 255 );
  1275.     HoldingPosition := Pos( ']' , HoldingString );
  1276.     if HoldingPosition = 0 then
  1277.     begin
  1278.       Result := HoldingString;
  1279.       exit;
  1280.     end
  1281.     else
  1282.     begin
  1283.       HoldingString := Copy( HoldingString , 1 , HoldingPosition - 1 );
  1284.       Result := HoldingString;
  1285.       exit;
  1286.     end;
  1287.   end;
  1288. end;
  1289.  
  1290. { This function takes a UNIX filespec and turns it into a Win16 filename }
  1291. function TFTPComponent.GetWin16FileName( InputName : String ) : String;
  1292. var WorkingString ,
  1293.     HoldingString   : String; { Holding string }
  1294. begin
  1295.   WorkingString := ExtractFileExt( InputName );
  1296.   if WorkingString = '' then
  1297.   begin
  1298.     if Length( InputName ) > 8 then
  1299.      WorkingString := Copy( InputName , 1 , 8 ) else
  1300.       WorkingString := InputName;
  1301.   end
  1302.   else
  1303.   begin
  1304.     if Length( WorkingString ) > 4 then
  1305.      WorkingString := Copy( WorkingString , 1 , 4 );
  1306.     HoldingString :=
  1307.      Copy( InputName , 1 , Pos( WorkingString , InputName ) - 1 );
  1308.     if Length( HoldingString ) > 8 then
  1309.      HoldingString := Copy( HoldingString , 1 , 8 );
  1310.     if HoldingString = '' then
  1311.     begin
  1312.       { Dot file }
  1313.       HoldingString := Copy( InputName , 2 , 255 ) + '.TXT';
  1314.       WorkingString := HoldingString;
  1315.     end
  1316.     else WorkingString := HoldingString + WorkingString;
  1317.   end;
  1318.   Result := WorkingString;
  1319. end;
  1320.  
  1321. { This sends a local file in binary mode to the remote server }
  1322. procedure TFTPComponent.SendBinaryLocalFile( LocalName : String );
  1323. var TheReturnString : String;  { Internal string holder }
  1324.     TheResult       : Integer; { Internal int holder    }
  1325.     Through         : Boolean;
  1326.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1327.     OutputFileHandle : Integer;
  1328.     TotalBytesSent ,
  1329.     BytesRead ,
  1330.     FileToSendSize    : Longint;
  1331.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1332. begin
  1333.   LocalName := ExpandFileName( LocalName );
  1334.   StrPCopy( FileNamePChar , LocalName );
  1335.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1336.   if OutputFileHandle = -1 then
  1337.   begin
  1338.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1339.      mtError , [mbOK] , 0 );
  1340.     exit;
  1341.   end;
  1342.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1343.   _llseek( OutputFileHandle , 0 , 0 );
  1344.   TheReturnString :=
  1345.    DoCStyleFormat( 'TYPE I' ,
  1346.     [ nil ] );
  1347.   { Put result in progress and status line }
  1348.   AddProgressText( TheReturnString );
  1349.   ShowProgressText( TheReturnString );
  1350.   { Send Password sequence }
  1351.   TheResult := PerformFTPCommand( 'TYPE I',
  1352.                                   [ nil ] );
  1353.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1354.   begin
  1355.     FTPCommandInProgress := false;
  1356.     exit;
  1357.   end;
  1358.   repeat
  1359.     TheResult := GetFTPServerResponse( TheReturnString );
  1360.     { Put result in progress and status line }
  1361.     AddProgressText( TheReturnString );
  1362.     ShowProgressText( TheReturnString );
  1363.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1364.   FTPCommandInProgress := false;
  1365.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1366.   begin
  1367.     { Do clever C formatting trick }
  1368.     TheReturnString :=
  1369.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1370.       [ nil ] );
  1371.     { Put result in progress and status line }
  1372.     AddProgressText( TheReturnString );
  1373.     ShowProgressErrorText( TheReturnString );
  1374.     { leave }
  1375.     exit;
  1376.   end
  1377.   else
  1378.   begin
  1379.     { Set up socket 2 for listening }
  1380.     Socket2.AsynchMode := False;
  1381.     Socket2.NonAsynchTimeoutValue := 60;
  1382.     { do a listen and send command to server that this is receipt socket }
  1383.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1384.     begin
  1385.       Socket2.CCSockCancelListen;
  1386.       exit;
  1387.     end;
  1388.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1389.     TheReturnString :=
  1390.      DoCStyleFormat( 'STOR %s' ,
  1391.       [ ExtractFileName( LocalName ) ] );
  1392.     { Put result in progress and status line }
  1393.     AddProgressText( TheReturnString );
  1394.     ShowProgressText( TheReturnString );
  1395.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName ) ] );
  1396.     GetFTPServerResponse( TheReturnString );
  1397.     AddProgressText( TheReturnString );
  1398.     ShowProgressText( TheReturnString );
  1399.     Socket1.NonAsynchTimeoutValue := 30;
  1400.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1401.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1402.     begin
  1403.       TheReturnString :=
  1404.        DoCStyleFormat( 'Could not create remote file!' ,
  1405.         [ nil ] );
  1406.       { Put result in progress and status line }
  1407.       AddProgressText( TheReturnString );
  1408.       ShowProgressErrorText( TheReturnString );
  1409.       Socket2.CCSockCancelListen;
  1410.       exit;
  1411.     end;
  1412.     Socket2.CCSockAccept;
  1413.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1414.     begin
  1415.       TheReturnString :=
  1416.        DoCStyleFormat( 'Could not establish send socket!' ,
  1417.         [ nil ] );
  1418.       { Put result in progress and status line }
  1419.       AddProgressText( TheReturnString );
  1420.       ShowProgressErrorText( TheReturnString );
  1421.       exit;
  1422.     end;
  1423.     Through := false;
  1424.     TotalBytesSent := 0;
  1425.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1426.     repeat
  1427.       if BytesRead = 0 then Through := true;
  1428.       if BytesRead > 0 then
  1429.       begin
  1430.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1431.         Socket2.StringData := TheReturnString;
  1432.         TotalBytesSent := TotalBytesSent + BytesRead;
  1433.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1434.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1435.         if BytesRead = -1 then
  1436.         begin
  1437.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1438.           GlobalAbortedFlag := True;
  1439.         end;
  1440.       end;
  1441.       if GlobalAbortedFlag then
  1442.       begin
  1443.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1444.         repeat
  1445.           TheResult := GetFTPServerResponse( TheReturnString );
  1446.           { Put result in progress and status line }
  1447.           AddProgressText( TheReturnString );
  1448.           ShowProgressText( TheReturnString );
  1449.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1450.         exit;
  1451.       end;
  1452.     until Through;
  1453.     FTPCommandInProgress := false;
  1454.     { cancel listening on second socket and close it }
  1455.     Socket2.CCSockCancelListen;
  1456.     Socket2.CCSockClose;
  1457.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1458.     AddProgressText( TheReturnString );
  1459.     ShowProgressText( TheReturnString );
  1460.     FTPCommandInProgress := false;
  1461.     PerformFTPCommand( 'TYPE A',
  1462.                                     [ nil ] );
  1463.     Through := false;
  1464.     repeat
  1465.       GetFTPServerResponse( TheReturnString );
  1466.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1467.        Through := true;
  1468.       { Put result in progress and status line }
  1469.       AddProgressText( TheReturnString );
  1470.       ShowProgressText( TheReturnString );
  1471.     until (( GlobalAbortedFlag ) or Through );
  1472.   end;
  1473.   _lclose( OutputFileHandle );
  1474.   FTPCommandInProgress := false;
  1475. end;
  1476.  
  1477. { This sends a local file in ascii mode to remote server }
  1478. procedure TFTPComponent.SendASCIILocalFile( LocalName : String );
  1479. var TheReturnString : String;  { Internal string holder }
  1480.     TheResult       : Integer; { Internal int holder    }
  1481.     Through         : Boolean;
  1482.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1483.     OutputFileHandle : Integer;
  1484.     TotalBytesSent ,
  1485.     BytesRead ,
  1486.     FileToSendSize    : Longint;
  1487.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1488. begin
  1489.   LocalName := ExpandFileName( LocalName );
  1490.   StrPCopy( FileNamePChar , LocalName );
  1491.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1492.   if OutputFileHandle = -1 then
  1493.   begin
  1494.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1495.      mtError , [mbOK] , 0 );
  1496.     exit;
  1497.   end;
  1498.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1499.   _llseek( OutputFileHandle , 0 , 0 );
  1500.   TheReturnString :=
  1501.    DoCStyleFormat( 'TYPE A' ,
  1502.     [ nil ] );
  1503.   { Put result in progress and status line }
  1504.   AddProgressText( TheReturnString );
  1505.   ShowProgressText( TheReturnString );
  1506.   { Send Password sequence }
  1507.   TheResult := PerformFTPCommand( 'TYPE A',
  1508.                                   [ nil ] );
  1509.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1510.   begin
  1511.     FTPCommandInProgress := false;
  1512.     exit;
  1513.   end;
  1514.   repeat
  1515.     TheResult := GetFTPServerResponse( TheReturnString );
  1516.     { Put result in progress and status line }
  1517.     AddProgressText( TheReturnString );
  1518.     ShowProgressText( TheReturnString );
  1519.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1520.   FTPCommandInProgress := false;
  1521.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1522.   begin
  1523.     { Do clever C formatting trick }
  1524.     TheReturnString :=
  1525.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1526.       [ nil ] );
  1527.     { Put result in progress and status line }
  1528.     AddProgressText( TheReturnString );
  1529.     ShowProgressErrorText( TheReturnString );
  1530.     { leave }
  1531.     exit;
  1532.   end
  1533.   else
  1534.   begin
  1535.     { Set up socket 2 for listening }
  1536.     Socket2.AsynchMode := False;
  1537.     Socket2.NonAsynchTimeoutValue := 60;
  1538.     { do a listen and send command to server that this is receipt socket }
  1539.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1540.     begin
  1541.       Socket2.CCSockCancelListen;
  1542.       exit;
  1543.     end;
  1544.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1545.     TheReturnString :=
  1546.      DoCStyleFormat( 'STOR %s' ,
  1547.       [ ExtractFileName( LocalName ) ] );
  1548.     { Put result in progress and status line }
  1549.     AddProgressText( TheReturnString );
  1550.     ShowProgressText( TheReturnString );
  1551.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName )]);
  1552.     GetFTPServerResponse( TheReturnString );
  1553.     AddProgressText( TheReturnString );
  1554.     ShowProgressText( TheReturnString );
  1555.     Socket1.NonAsynchTimeoutValue := 30;
  1556.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1557.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1558.     begin
  1559.       TheReturnString :=
  1560.        DoCStyleFormat( 'Could not create remote file!' ,
  1561.         [ nil ] );
  1562.       { Put result in progress and status line }
  1563.       AddProgressText( TheReturnString );
  1564.       ShowProgressErrorText( TheReturnString );
  1565.       Socket2.CCSockCancelListen;
  1566.       exit;
  1567.     end;
  1568.     Socket2.CCSockAccept;
  1569.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1570.     begin
  1571.       TheReturnString :=
  1572.        DoCStyleFormat( 'Could not establish send socket!' ,
  1573.         [ nil ] );
  1574.       { Put result in progress and status line }
  1575.       AddProgressText( TheReturnString );
  1576.       ShowProgressErrorText( TheReturnString );
  1577.       exit;
  1578.     end;
  1579.     Through := false;
  1580.     TotalBytesSent := 0;
  1581.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1582.     repeat
  1583.       if BytesRead = 0 then Through := true;
  1584.       if BytesRead > 0 then
  1585.       begin
  1586.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1587.         Socket2.StringData := TheReturnString;
  1588.         TotalBytesSent := TotalBytesSent + BytesRead;
  1589.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1590.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1591.         if BytesRead = -1 then
  1592.         begin
  1593.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1594.           GlobalAbortedFlag := True;
  1595.         end;
  1596.       end;
  1597.       if GlobalAbortedFlag then
  1598.       begin
  1599.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1600.         repeat
  1601.           TheResult := GetFTPServerResponse( TheReturnString );
  1602.           { Put result in progress and status line }
  1603.           AddProgressText( TheReturnString );
  1604.           ShowProgressText( TheReturnString );
  1605.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1606.         exit;
  1607.       end;
  1608.     until Through;
  1609.     { cancel listening on second socket and close it }
  1610.     Socket2.CCSockCancelListen;
  1611.     Socket2.CCSockClose;
  1612.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1613.     AddProgressText( TheReturnString );
  1614.     ShowProgressText( TheReturnString );
  1615.     FTPCommandInProgress := false;
  1616.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1617.     Through := false;
  1618.     repeat
  1619.       GetFTPServerResponse( TheReturnString );
  1620.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1621.        Through := true;
  1622.       { Put result in progress and status line }
  1623.       AddProgressText( TheReturnString );
  1624.       ShowProgressText( TheReturnString );
  1625.     until (( GlobalAbortedFlag ) or Through );
  1626.   end;
  1627.   _lclose( OutputFileHandle );
  1628.   FTPCommandInProgress := false;
  1629. end;
  1630.  
  1631. { This function strips out the FTP response for bytes to send }
  1632. function TFTPComponent.GetTotalBytesToReceive( TheString : String ) : Longint;
  1633. var
  1634.   LeftPosition ,
  1635.   RightPosition  : integer;
  1636.   TempString     : string;
  1637. begin
  1638.   LeftPosition := Pos( '(' , TheString );
  1639.   TempString := Copy( TheString ,
  1640.                       LeftPosition + 1 , 255 );
  1641.   RightPosition := Pos( ' ' , TempString );
  1642.   if (( LeftPosition = 0 ) or ( RightPosition = 0 )) then
  1643.   begin
  1644.     Result := 0;
  1645.     exit;
  1646.   end;
  1647.   if RightPosition <> 0 then
  1648.     TempString := Copy( TempString , 1 , RightPosition - 1  );
  1649.   try
  1650.     Result := StrToInt( TempString );
  1651.   except
  1652.     on EConvertError do Result := 0;
  1653.   end;
  1654. end;
  1655.  
  1656. procedure TFTPComponent.UpdateGauge( BytesFinished , TotalToHandle : longint );
  1657. begin
  1658.   CCInetCCForm.UpdateGauge( BytesFinished , TotalToHandle );
  1659. end;
  1660.  
  1661. { This sends FTP progress text to the Inet form }
  1662. procedure TFTPComponent.AddProgressText( WhatText : String );
  1663. begin
  1664.   CCInetCCForm.AddProgressText( WhatText );
  1665. end;
  1666.  
  1667. { This sends FTP progress text to the Inet form }
  1668. procedure TFTPComponent.ShowProgressText( WhatText : String );
  1669. begin
  1670.   CCInetCCForm.ShowProgressText( WhatText );
  1671. end;
  1672.  
  1673. { This procedure receives a binary remote file }
  1674. procedure TFTPComponent.ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  1675. var TheReturnString : String;  { Internal string holder }
  1676.     TheResult       : Integer; { Internal int holder    }
  1677.     Through         : Boolean;
  1678.     TotalBytesSent ,
  1679.     FileToGetSize    : Longint;
  1680. begin
  1681.   TheReturnString :=
  1682.    DoCStyleFormat( 'TYPE A' ,
  1683.     [ nil ] );
  1684.   { Put result in progress and status line }
  1685.   AddProgressText( TheReturnString );
  1686.   ShowProgressText( TheReturnString );
  1687.   { Send Password sequence }
  1688.   FTPCommandInProgress := false;
  1689.   TheResult := PerformFTPCommand( 'TYPE A',
  1690.                                   [ nil ] );
  1691.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1692.   begin
  1693.     FTPCommandInProgress := false;
  1694.     exit;
  1695.   end;
  1696.   repeat
  1697.     TheResult := GetFTPServerResponse( TheReturnString );
  1698.     { Put result in progress and status line }
  1699.     AddProgressText( TheReturnString );
  1700.     ShowProgressText( TheReturnString );
  1701.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1702.   FTPCommandInProgress := false;
  1703.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1704.   begin
  1705.     { Do clever C formatting trick }
  1706.     TheReturnString :=
  1707.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1708.       [ nil ] );
  1709.     { Put result in progress and status line }
  1710.     AddProgressText( TheReturnString );
  1711.     ShowProgressErrorText( TheReturnString );
  1712.     { leave }
  1713.     exit;
  1714.   end
  1715.   else
  1716.   begin
  1717.     { Set up socket 2 for listening }
  1718.     Socket2.AsynchMode := False;
  1719.     Socket2.NonAsynchTimeoutValue := 60;
  1720.     { do a listen and send command to server that this is receipt socket }
  1721.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1722.     begin
  1723.       Socket2.CCSockCancelListen;
  1724.       exit;
  1725.     end;
  1726.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1727.     TheReturnString :=
  1728.      DoCStyleFormat( 'RETR %s' ,
  1729.       [ RemoteName ] );
  1730.     { Put result in progress and status line }
  1731.     AddProgressText( TheReturnString );
  1732.     ShowProgressText( TheReturnString );
  1733.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1734.     GetFTPServerResponse( TheReturnString );
  1735.     AddProgressText( TheReturnString );
  1736.     ShowProgressText( TheReturnString );
  1737.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1738.     Socket1.NonAsynchTimeoutValue := 30;
  1739.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1740.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1741.     begin
  1742.       TheReturnString :=
  1743.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1744.         [ nil ] );
  1745.       { Put result in progress and status line }
  1746.       AddProgressText( TheReturnString );
  1747.       ShowProgressErrorText( TheReturnString );
  1748.       Socket2.CCSockCancelListen;
  1749.       exit;
  1750.     end;
  1751.     Socket2.CCSockAccept;
  1752.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1753.     begin
  1754.       TheReturnString :=
  1755.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1756.         [ nil ] );
  1757.       { Put result in progress and status line }
  1758.       AddProgressText( TheReturnString );
  1759.       ShowProgressErrorText( TheReturnString );
  1760.       exit;
  1761.     end;
  1762.     Through := false;
  1763.     TotalBytesSent := 0;
  1764.     repeat
  1765.       TheReturnString := Socket2.StringData;
  1766.       if Length( TheReturnString ) = 0 then Through := true;
  1767.       if Length( TheReturnString ) > 0 then
  1768.       begin
  1769.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1770.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1771.         { Put result in progress and status line }
  1772.         AddProgressText( TheReturnString );
  1773.         ShowProgressText( TheReturnString );
  1774.       end;
  1775.       if GlobalAbortedFlag then
  1776.       begin
  1777.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1778.         repeat
  1779.           TheResult := GetFTPServerResponse( TheReturnString );
  1780.           { Put result in progress and status line }
  1781.           AddProgressText( TheReturnString );
  1782.           ShowProgressText( TheReturnString );
  1783.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1784.         exit;
  1785.       end;
  1786.     until Through;
  1787.     { cancel listening on second socket and close it }
  1788.     Socket2.CCSockCancelListen;
  1789.     Socket2.CCSockClose;
  1790.     FTPCommandInProgress := false;
  1791.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1792.     Through := false;
  1793.     repeat
  1794.       GetFTPServerResponse( TheReturnString );
  1795.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1796.        Through := true;
  1797.       { Put result in progress and status line }
  1798.       AddProgressText( TheReturnString );
  1799.       ShowProgressText( TheReturnString );
  1800.     until (( GlobalAbortedFlag ) or Through );
  1801.   end;
  1802.   FTPCommandInProgress := false;
  1803. end;
  1804.  
  1805. { This procedure receives a binary remote file }
  1806. procedure TFTPComponent.ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  1807. var TheReturnString : String;  { Internal string holder }
  1808.     TheResult       : Integer; { Internal int holder    }
  1809.     Through         : Boolean;
  1810.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1811.     OutputFileHandle : Integer;
  1812.     TotalBytesSent ,
  1813.     FileToGetSize    : Longint;
  1814.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1815. begin
  1816.   LocalName := ExpandFileName( LocalName );
  1817.   StrPCopy( FileNamePChar , LocalName );
  1818.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1819.   if OutputFileHandle = -1 then
  1820.   begin
  1821.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1822.      mtError , [mbOK] , 0 );
  1823.     exit;
  1824.   end;
  1825.   TheReturnString :=
  1826.    DoCStyleFormat( 'TYPE A' ,
  1827.     [ nil ] );
  1828.   { Put result in progress and status line }
  1829.   AddProgressText( TheReturnString );
  1830.   ShowProgressText( TheReturnString );
  1831.   { Send Password sequence }
  1832.   TheResult := PerformFTPCommand( 'TYPE A',
  1833.                                   [ nil ] );
  1834.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1835.   begin
  1836.     FTPCommandInProgress := false;
  1837.     exit;
  1838.   end;
  1839.   repeat
  1840.     TheResult := GetFTPServerResponse( TheReturnString );
  1841.     { Put result in progress and status line }
  1842.     AddProgressText( TheReturnString );
  1843.     ShowProgressText( TheReturnString );
  1844.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1845.   FTPCommandInProgress := false;
  1846.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1847.   begin
  1848.     { Do clever C formatting trick }
  1849.     TheReturnString :=
  1850.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1851.       [ nil ] );
  1852.     { Put result in progress and status line }
  1853.     AddProgressText( TheReturnString );
  1854.     ShowProgressErrorText( TheReturnString );
  1855.     { leave }
  1856.     exit;
  1857.   end
  1858.   else
  1859.   begin
  1860.     { Set up socket 2 for listening }
  1861.     Socket2.AsynchMode := False;
  1862.     Socket2.NonAsynchTimeoutValue := 60;
  1863.     { do a listen and send command to server that this is receipt socket }
  1864.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1865.     begin
  1866.       Socket2.CCSockCancelListen;
  1867.       exit;
  1868.     end;
  1869.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1870.     TheReturnString :=
  1871.      DoCStyleFormat( 'RETR %s' ,
  1872.       [ RemoteName ] );
  1873.     { Put result in progress and status line }
  1874.     AddProgressText( TheReturnString );
  1875.     ShowProgressText( TheReturnString );
  1876.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1877.     GetFTPServerResponse( TheReturnString );
  1878.     AddProgressText( TheReturnString );
  1879.     ShowProgressText( TheReturnString );
  1880.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1881.     Socket1.NonAsynchTimeoutValue := 30;
  1882.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1883.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1884.     begin
  1885.       TheReturnString :=
  1886.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1887.         [ nil ] );
  1888.       { Put result in progress and status line }
  1889.       AddProgressText( TheReturnString );
  1890.       ShowProgressErrorText( TheReturnString );
  1891.       Socket2.CCSockCancelListen;
  1892.       exit;
  1893.     end;
  1894.     Socket2.CCSockAccept;
  1895.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1896.     begin
  1897.       TheReturnString :=
  1898.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1899.         [ nil ] );
  1900.       { Put result in progress and status line }
  1901.       AddProgressText( TheReturnString );
  1902.       ShowProgressErrorText( TheReturnString );
  1903.       exit;
  1904.     end;
  1905.     Through := false;
  1906.     TotalBytesSent := 0;
  1907.     repeat
  1908.       TheReturnString := Socket2.StringData;
  1909.       if Length( TheReturnString ) = 0 then Through := true;
  1910.       if Length( TheReturnString ) > 0 then
  1911.       begin
  1912.         StrPCopy( CopyBuffer , TheReturnString );
  1913.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1914.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1915.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  1916.          = -1 then
  1917.         begin
  1918.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  1919.           GlobalAbortedFlag := True;
  1920.         end;
  1921.       end;
  1922.       if GlobalAbortedFlag then
  1923.       begin
  1924.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1925.         repeat
  1926.           TheResult := GetFTPServerResponse( TheReturnString );
  1927.           { Put result in progress and status line }
  1928.           AddProgressText( TheReturnString );
  1929.           ShowProgressText( TheReturnString );
  1930.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1931.         exit;
  1932.       end;
  1933.     until Through;
  1934.     { cancel listening on second socket and close it }
  1935.     Socket2.CCSockCancelListen;
  1936.     Socket2.CCSockClose;
  1937.     FTPCommandInProgress := false;
  1938.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1939.     Through := false;
  1940.     repeat
  1941.       GetFTPServerResponse( TheReturnString );
  1942.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1943.        Through := true;
  1944.       { Put result in progress and status line }
  1945.       AddProgressText( TheReturnString );
  1946.       ShowProgressText( TheReturnString );
  1947.     until (( GlobalAbortedFlag ) or Through );
  1948.   end;
  1949.   _lclose( OutputFileHandle );
  1950.   FTPCommandInProgress := false;
  1951. end;
  1952.  
  1953. { This procedure receives a binary remote file }
  1954. procedure TFTPComponent.ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  1955. var TheReturnString : String;  { Internal string holder }
  1956.     TheResult       : Integer; { Internal int holder    }
  1957.     Through         : Boolean;
  1958.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1959.     OutputFileHandle : Integer;
  1960.     TotalBytesSent ,
  1961.     FileToGetSize    : Longint;
  1962.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1963. begin
  1964.   LocalName := ExpandFileName( LocalName );
  1965.   StrPCopy( FileNamePChar , LocalName );
  1966.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1967.   if OutputFileHandle = -1 then
  1968.   begin
  1969.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1970.      mtError , [mbOK] , 0 );
  1971.     exit;
  1972.   end;
  1973.   TheReturnString :=
  1974.    DoCStyleFormat( 'TYPE I' ,
  1975.     [ nil ] );
  1976.   { Put result in progress and status line }
  1977.   AddProgressText( TheReturnString );
  1978.   ShowProgressText( TheReturnString );
  1979.   { Send Password sequence }
  1980.   TheResult := PerformFTPCommand( 'TYPE I',
  1981.                                   [ nil ] );
  1982.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1983.   begin
  1984.     FTPCommandInProgress := false;
  1985.     exit;
  1986.   end;
  1987.   repeat
  1988.     TheResult := GetFTPServerResponse( TheReturnString );
  1989.     { Put result in progress and status line }
  1990.     AddProgressText( TheReturnString );
  1991.     ShowProgressText( TheReturnString );
  1992.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1993.   FTPCommandInProgress := false;
  1994.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1995.   begin
  1996.     { Do clever C formatting trick }
  1997.     TheReturnString :=
  1998.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1999.       [ nil ] );
  2000.     { Put result in progress and status line }
  2001.     AddProgressText( TheReturnString );
  2002.     ShowProgressErrorText( TheReturnString );
  2003.     { leave }
  2004.     exit;
  2005.   end
  2006.   else
  2007.   begin
  2008.     { Set up socket 2 for listening }
  2009.     Socket2.AsynchMode := False;
  2010.     Socket2.NonAsynchTimeoutValue := 60;
  2011.     { do a listen and send command to server that this is receipt socket }
  2012.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2013.     begin
  2014.       Socket2.CCSockCancelListen;
  2015.       exit;
  2016.     end;
  2017.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2018.     TheReturnString :=
  2019.      DoCStyleFormat( 'RETR %s' ,
  2020.       [ RemoteName ] );
  2021.     { Put result in progress and status line }
  2022.     AddProgressText( TheReturnString );
  2023.     ShowProgressText( TheReturnString );
  2024.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  2025.     GetFTPServerResponse( TheReturnString );
  2026.     AddProgressText( TheReturnString );
  2027.     ShowProgressText( TheReturnString );
  2028.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  2029.     Socket1.NonAsynchTimeoutValue := 30;
  2030.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2031.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2032.     begin
  2033.       TheReturnString :=
  2034.        DoCStyleFormat( 'Could not obtain remote file!' ,
  2035.         [ nil ] );
  2036.       { Put result in progress and status line }
  2037.       AddProgressText( TheReturnString );
  2038.       ShowProgressErrorText( TheReturnString );
  2039.       Socket2.CCSockCancelListen;
  2040.       exit;
  2041.     end;
  2042.     Socket2.CCSockAccept;
  2043.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2044.     begin
  2045.       TheReturnString :=
  2046.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2047.         [ nil ] );
  2048.       { Put result in progress and status line }
  2049.       AddProgressText( TheReturnString );
  2050.       ShowProgressErrorText( TheReturnString );
  2051.       exit;
  2052.     end;
  2053.     Through := false;
  2054.     TotalBytesSent := 0;
  2055.     repeat
  2056.       TheReturnString := Socket2.StringData;
  2057.       if Length( TheReturnString ) = 0 then Through := true;
  2058.       if Length( TheReturnString ) > 0 then
  2059.       begin
  2060.         StrPCopy( CopyBuffer , TheReturnString );
  2061.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  2062.         UpdateGauge( TotalBytesSent , FileToGetSize );
  2063.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  2064.          = -1 then
  2065.         begin
  2066.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  2067.           GlobalAbortedFlag := True;
  2068.         end;
  2069.       end;
  2070.       if GlobalAbortedFlag then
  2071.       begin
  2072.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2073.         repeat
  2074.           TheResult := GetFTPServerResponse( TheReturnString );
  2075.           { Put result in progress and status line }
  2076.           AddProgressText( TheReturnString );
  2077.           ShowProgressText( TheReturnString );
  2078.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2079.         exit;
  2080.       end;
  2081.     until Through;
  2082.     { cancel listening on second socket and close it }
  2083.     Socket2.CCSockCancelListen;
  2084.     Socket2.CCSockClose;
  2085.     FTPCommandInProgress := false;
  2086.     PerformFTPCommand( 'TYPE A', [ nil ] );
  2087.     Through := false;
  2088.     repeat
  2089.       GetFTPServerResponse( TheReturnString );
  2090.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  2091.        Through := true;
  2092.       { Put result in progress and status line }
  2093.       AddProgressText( TheReturnString );
  2094.       ShowProgressText( TheReturnString );
  2095.     until (( GlobalAbortedFlag ) or Through );
  2096.   end;
  2097.   _lclose( OutputFileHandle );
  2098.   FTPCommandInProgress := false;
  2099. end;
  2100.  
  2101. { This sends FTP progress text to the Inet form }
  2102. procedure TFTPComponent.ShowProgressErrorText( WhatText : String );
  2103. begin
  2104.   CCInetCCForm.ShowProgressErrorText( WhatText );
  2105. end;
  2106.  
  2107. { This is a core function! It performs an FTP command and if no timeout }
  2108. { return a preliminary ok.                                              }
  2109. function TFTPComponent.PerformFTPCommand(
  2110.                  TheCommand        : string;
  2111.            const TheArguments      : array of const ) : Integer;
  2112. var TheBuffer : string; { Text buffer }
  2113. begin
  2114.   { If command in progress send back -1 error }
  2115.   if FTPCommandInProgress then
  2116.   begin
  2117.     Result := -1;
  2118.     exit;
  2119.   end;
  2120.   { Set status variable }
  2121.   FTPCommandInProgress := True;
  2122.   { Set global error code }
  2123.   GlobalErrorCode := 0;
  2124.   { Format output string }
  2125.   TheBuffer := Format( TheCommand , TheArguments );
  2126.   { Preset failure code }
  2127.   Result := TCPIP_STATUS_FATAL_ERROR;
  2128.   { If invalid socket or no connection abort }
  2129.   if ( Socket1.TheSocket = INVALID_SOCKET ) or not Connection_Established then
  2130.    exit;
  2131.   { Send the buffer plus EOL chars }
  2132.   Socket1.StringData := TheBuffer + #13#10;
  2133.   { if abort due to timeout or other error exit }
  2134.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2135.   { Otherwise return preliminary code }
  2136.   Result := TCPIP_STATUS_PRELIMINARY;
  2137. end;
  2138.  
  2139. { This function gets up to 255 chars of data plus a return code from FTP serv }
  2140. function TFTPComponent.GetFTPServerResponse(
  2141.           var ResponseString : String ) : integer;
  2142. var
  2143.   { Buffer string for response line }
  2144.   TheBuffer     : string;
  2145.   { Pointer to the response string }
  2146.   BufferPointer : array[0..255] of char absolute TheBuffer;
  2147.   { Character to check for response code }
  2148.   ResponseChar   : char;
  2149.   { Pointers into returned string }
  2150.   TheIndex ,
  2151.   TheLength     : integer;
  2152.   { Control variable }
  2153.   LeftoversInPan ,
  2154.   Finished      : Boolean;
  2155. begin
  2156.   { Preset fatal error }
  2157.   Result := TCPIP_STATUS_FATAL_ERROR;
  2158.   { Start loop control }
  2159.   LeftoversInPan := false;
  2160.   Finished := false;
  2161.   repeat
  2162.     { Do a peek }
  2163.     TheBuffer := Socket1.PeekData;
  2164.     { If timeout or other error exit }
  2165.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2166.     { Find end of line character }
  2167.     TheIndex := Pos( #10 , TheBuffer );
  2168.     if TheIndex = 0 then
  2169.     begin
  2170.       TheIndex := Pos( #13 , TheBuffer );
  2171.       if TheIndex = 0 then
  2172.       begin
  2173.         TheIndex := Pos( #0 , TheBuffer );
  2174.         if TheIndex = 0 then
  2175.         begin
  2176.           TheIndex := Length( TheBuffer );
  2177.           LeftoversInPan := True;
  2178.           LeftoverText := LeftoverText + TheBuffer;
  2179.           LeftoversOnTable := false;
  2180.         end;
  2181.       end;
  2182.     end;
  2183.     { If an end of line then process the line }
  2184.     if TheIndex > 0 then
  2185.     begin
  2186.       { Get length of string }
  2187.       TheLength := TheIndex;
  2188.       { Receive actual data }
  2189.       Socket1.CCSockReceive( Socket1.TheSocket   ,
  2190.                              @BufferPointer[ 1 ] ,
  2191.                              TheLength              );
  2192.       { Abort if timeout or error }
  2193.       if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2194.       { Put in the length byte }
  2195.       BufferPointer[ 0 ] := Chr( TheLength );
  2196.       if LeftOversOnTable then
  2197.       begin
  2198.         LeftOversOnTable := false;
  2199.         ResponseString := LeftoverText + TheBuffer;
  2200.         TheBuffer := ResponseString;
  2201.         LeftoverText := '';
  2202.       end;
  2203.       if LeftoversInPan then
  2204.       begin
  2205.         LeftoversInPan := false;
  2206.         LeftoversOnTable := true;
  2207.       end;
  2208.       { If not a continuation line }
  2209.       if TheBuffer[ 4 ] <> '-' then
  2210.       begin
  2211.         { Get first number character }
  2212.         ResponseChar := TheBuffer[ 1 ];
  2213.         { Get the value of the number from 1 to 5 }
  2214.         if (( ResponseChar >= '1' ) and ( ResponseChar <= '5' )) then
  2215.         begin
  2216.           Finished := true;
  2217.           Result := Ord( ResponseChar ) - 48;
  2218.         end;
  2219.       end
  2220.       else
  2221.       begin
  2222.         { otherwise return preliminary result }
  2223.         Finished := true;
  2224.         Result := TCPIP_STATUS_PRELIMINARY;
  2225.       end;
  2226.     end
  2227.     else
  2228.     begin
  2229.     end;
  2230.   until ( Finished and ( not LeftoversOnTable ));
  2231.   { Return buffer as response string }
  2232.   ResponseString := TheBuffer;
  2233. end;
  2234.  
  2235. { Boilerplate error routine }
  2236. procedure TFTPComponent.FTPSocketsErrorOccurred( Sender     : TObject;
  2237.                                                  ErrorCode  : Integer;
  2238.                                                  TheMessage : String   );
  2239. begin
  2240.   CCInetCCForm.SocketsErrorOccurred( Sender,ErrorCode,TheMessage );
  2241. end;
  2242.  
  2243. { This is the FTP components initial connection routine }
  2244. function TFTPComponent.EstablishConnection(
  2245.           PCRPointer : PConnectionsRecord ) : Boolean;
  2246. var TheReturnString : String;  { Internal string holder }
  2247.     TheResult       : Integer; { Internal int holder    }
  2248. begin
  2249.   { Set default FTP Port value }
  2250.   Socket1.PortName := '21';
  2251.   { Get the ip address from the record }
  2252.   Socket1.IPAddressName := PCRPointer^.CIPAddress;
  2253.   { Set blocking mode }
  2254.   Socket1.AsynchMode := False;
  2255.   { Clear condition variables }
  2256.   GlobalErrorCode := 0;
  2257.   GlobalAbortedFlag := false;
  2258.   { Actually attempt to connect }
  2259.   Socket1.CCSockConnect;
  2260.   { Check if connected }
  2261.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 ) or
  2262.       ( Socket1.TheSocket = INVALID_SOCKET )) then
  2263.   begin { Didn't connect; signal error and abort }
  2264.     { Do clever C formatting trick }
  2265.     TheReturnString :=
  2266.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2267.       [ PCRPointer^.CIPAddress ] );
  2268.     { Put result in progress and status line }
  2269.     AddProgressText( TheReturnString );
  2270.     ShowProgressErrorText( TheReturnString );
  2271.     { Signal error }
  2272.     Result := False;
  2273.     { leave }
  2274.     exit;
  2275.   end
  2276.   else
  2277.   begin
  2278.     Connection_Established := true;
  2279.     { Signal successful connection }
  2280.     TheReturnString := DoCStyleFormat(
  2281.       'Connected on Local port: %s with IP: %s',
  2282.       [ Socket1.GetSocketPort( Socket1.TheSocket ),
  2283.         Socket1.GetSocketIPAddress( Socket1.TheSocket )]);
  2284.     { Put result in progress and status line }
  2285.     CCINetCCForm.AddProgressText( TheReturnString );
  2286.     CCINetCCForm.ShowProgressText( TheReturnString );
  2287.     TheReturnString := DoCStyleFormat(
  2288.      'Connected to Remote port: %s with IP: %s',
  2289.       [ Socket1.GetSocketPeerPort( Socket1.TheSocket ),
  2290.         Socket1.GetSocketPeerIPAddress( Socket1.TheSocket )]);
  2291.     { Put result in progress and status line }
  2292.     CCINetCCForm.AddProgressText( TheReturnString );
  2293.     CCINetCCForm.ShowProgressText( TheReturnString );
  2294.     TheReturnString := DoCStyleFormat( 'Successfully connected to %s',
  2295.      [ Socket1.IPAddressName ]);
  2296.     { Put result in progress and status line }
  2297.     CCINetCCForm.AddProgressText( TheReturnString );
  2298.     CCINetCCForm.ShowProgressText( TheReturnString );
  2299.     repeat
  2300.       TheResult := GetFTPServerResponse( TheReturnString );
  2301.       { Put result in progress and status line }
  2302.       AddProgressText( TheReturnString );
  2303.       ShowProgressText( TheReturnString );
  2304.     until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2305.     if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2306.     begin
  2307.       { Do clever C formatting trick }
  2308.       TheReturnString :=
  2309.        DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2310.         [ PCRPointer^.CIPAddress ] );
  2311.       { Put result in progress and status line }
  2312.       AddProgressText( TheReturnString );
  2313.       ShowProgressErrorText( TheReturnString );
  2314.       { Signal error }
  2315.       Result := False;
  2316.       { leave }
  2317.       exit;
  2318.     end
  2319.     else Result := true; { Signal no problem }
  2320.   end;
  2321. end;
  2322.  
  2323. { This is the FTP components USER login routine }
  2324. function TFTPComponent.LoginUser(
  2325.           PCRPointer : PConnectionsRecord ) : Boolean;
  2326. var TheReturnString : String;  { Internal string holder }
  2327.     TheResult       : Integer; { Internal int holder    }
  2328. begin
  2329.   TheReturnString :=
  2330.    DoCStyleFormat( 'USER %s' ,
  2331.     [ PCRPointer^.CUserName ] );
  2332.   { Put result in progress and status line }
  2333.   AddProgressText( TheReturnString );
  2334.   ShowProgressText( TheReturnString );
  2335.   { Begin login sequence with user name }
  2336.   TheResult := PerformFTPCommand( 'USER %s',
  2337.                                   [ PCRPointer^.CUserName ] );
  2338.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2339.   begin
  2340.     FTPCommandInProgress := false;
  2341.     Result := false;
  2342.     exit;
  2343.   end;
  2344.   repeat
  2345.     TheResult := GetFTPServerResponse( TheReturnString );
  2346.     { Put result in progress and status line }
  2347.     AddProgressText( TheReturnString );
  2348.     ShowProgressText( TheReturnString );
  2349.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2350.   FTPCommandInProgress := false;
  2351.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_CONTINUING )) then
  2352.   begin
  2353.     { Do clever C formatting trick }
  2354.     TheReturnString :=
  2355.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2356.       [ PCRPointer^.CIPAddress ] );
  2357.     { Put result in progress and status line }
  2358.     AddProgressText( TheReturnString );
  2359.     ShowProgressErrorText( TheReturnString );
  2360.     { Signal error }
  2361.     Result := False;
  2362.     { leave }
  2363.     exit;
  2364.   end
  2365.   else Result := true; { Signal no problem }
  2366. end;
  2367.  
  2368. function TFTPComponent.DeleteRemoteDirectory( TheDir : String ) : Boolean;
  2369. var TheReturnString : String;  { Internal string holder }
  2370.     TheResult       : Integer; { Internal int holder    }
  2371. begin
  2372.   TheReturnString := DoCStyleFormat( 'RMD %s' ,
  2373.    [ TheDir ] );
  2374.   { Put result in progress and status line }
  2375.   AddProgressText( TheReturnString );
  2376.   ShowProgressText( TheReturnString );
  2377.   { Send Password sequence }
  2378.   TheResult := PerformFTPCommand( 'RMD %s',
  2379.                                   [ TheDir ] );
  2380.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2381.   begin
  2382.     Result := false;
  2383.     FTPCommandInProgress := false;
  2384.     exit;
  2385.   end;
  2386.   repeat
  2387.     TheResult := GetFTPServerResponse( TheReturnString );
  2388.     { Put result in progress and status line }
  2389.     AddProgressText( TheReturnString );
  2390.     ShowProgressText( TheReturnString );
  2391.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2392.   FTPCommandInProgress := false;
  2393.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2394.   begin
  2395.     { Do clever C formatting trick }
  2396.     TheReturnString :=
  2397.      DoCStyleFormat( 'Delete Directory %s Failed!' ,
  2398.       [ TheDir ] );
  2399.     { Put result in progress and status line }
  2400.     AddProgressText( TheReturnString );
  2401.     ShowProgressErrorText( TheReturnString );
  2402.     { Signal error }
  2403.     Result := False;
  2404.     { leave }
  2405.     exit;
  2406.   end
  2407.   else Result := true; { Signal no problem }
  2408. end;
  2409.  
  2410. function TFTPComponent.CreateRemoteDirectory( TheDir : String ) : Boolean;
  2411. var TheReturnString : String;  { Internal string holder }
  2412.     TheResult       : Integer; { Internal int holder    }
  2413. begin
  2414.   TheReturnString := DoCStyleFormat( 'MKD %s' ,
  2415.     [ TheDir ] );
  2416.   { Put result in progress and status line }
  2417.   AddProgressText( TheReturnString );
  2418.   ShowProgressText( TheReturnString );
  2419.   { Send Password sequence }
  2420.   TheResult := PerformFTPCommand( 'MKD %s',
  2421.                                   [ TheDir ] );
  2422.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2423.   begin
  2424.     Result := false;
  2425.     FTPCommandInProgress := false;
  2426.     exit;
  2427.   end;
  2428.   repeat
  2429.     TheResult := GetFTPServerResponse( TheReturnString );
  2430.     { Put result in progress and status line }
  2431.     AddProgressText( TheReturnString );
  2432.     ShowProgressText( TheReturnString );
  2433.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2434.   FTPCommandInProgress := false;
  2435.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2436.   begin
  2437.     { Do clever C formatting trick }
  2438.     TheReturnString :=
  2439.      DoCStyleFormat( 'Create Directory %s Failed!' ,
  2440.       [ TheDir ] );
  2441.     { Put result in progress and status line }
  2442.     AddProgressText( TheReturnString );
  2443.     ShowProgressErrorText( TheReturnString );
  2444.     { Signal error }
  2445.     Result := False;
  2446.     { leave }
  2447.     exit;
  2448.   end
  2449.   else Result := true; { Signal no problem }
  2450. end;
  2451.  
  2452.  
  2453. function TFTPComponent.DeleteRemoteFile( TheFileName : String ) : Boolean;
  2454. var TheReturnString : String;  { Internal string holder }
  2455.     TheResult       : Integer; { Internal int holder    }
  2456. begin
  2457.   TheReturnString := DoCStyleFormat( 'DELE %s' ,
  2458.     [ TheFileName ] );
  2459.   { Put result in progress and status line }
  2460.   AddProgressText( TheReturnString );
  2461.   ShowProgressText( TheReturnString );
  2462.   { Send Password sequence }
  2463.   TheResult := PerformFTPCommand( 'DELE %s',
  2464.                                   [ TheFileName ] );
  2465.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2466.   begin
  2467.     Result := false;
  2468.     FTPCommandInProgress := false;
  2469.     exit;
  2470.   end;
  2471.   repeat
  2472.     TheResult := GetFTPServerResponse( TheReturnString );
  2473.     { Put result in progress and status line }
  2474.     AddProgressText( TheReturnString );
  2475.     ShowProgressText( TheReturnString );
  2476.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2477.   FTPCommandInProgress := false;
  2478.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2479.   begin
  2480.     { Do clever C formatting trick }
  2481.     TheReturnString :=
  2482.      DoCStyleFormat( 'Delete File %s Failed!' ,
  2483.       [ TheFileName ] );
  2484.     { Put result in progress and status line }
  2485.     AddProgressText( TheReturnString );
  2486.     ShowProgressErrorText( TheReturnString );
  2487.     { Signal error }
  2488.     Result := False;
  2489.     { leave }
  2490.     exit;
  2491.   end
  2492.   else Result := true; { Signal no problem }
  2493. end;
  2494.  
  2495. { This is the FTP components PASSWORD routine }
  2496. function TFTPComponent.SendPassword(
  2497.           PCRPointer : PConnectionsRecord ) : Boolean;
  2498. var TheReturnString : String;  { Internal string holder }
  2499.     TheResult       : Integer; { Internal int holder    }
  2500. begin
  2501.   TheReturnString := 'PASS XXXXXX' + #13#10;
  2502.   { Put result in progress and status line }
  2503.   AddProgressText( TheReturnString );
  2504.   ShowProgressText( TheReturnString );
  2505.   { Send Password sequence }
  2506.   TheResult := PerformFTPCommand( 'PASS %s',
  2507.                                   [ PCRPointer^.CPassword ] );
  2508.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2509.   begin
  2510.     Result := false;
  2511.     FTPCommandInProgress := false;
  2512.     exit;
  2513.   end;
  2514.   repeat
  2515.     TheResult := GetFTPServerResponse( TheReturnString );
  2516.     { Put result in progress and status line }
  2517.     AddProgressText( TheReturnString );
  2518.     ShowProgressText( TheReturnString );
  2519.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2520.   FTPCommandInProgress := false;
  2521.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2522.   begin
  2523.     { Do clever C formatting trick }
  2524.     TheReturnString :=
  2525.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2526.       [ PCRPointer^.CIPAddress ] );
  2527.     { Put result in progress and status line }
  2528.     AddProgressText( TheReturnString );
  2529.     ShowProgressErrorText( TheReturnString );
  2530.     { Signal error }
  2531.     Result := False;
  2532.     { leave }
  2533.     exit;
  2534.   end
  2535.   else Result := true; { Signal no problem }
  2536. end;
  2537.  
  2538. { This is the FTP components CWD routine }
  2539. function TFTPComponent.SetRemoteStartupDirectory(
  2540.           PCRPointer : PConnectionsRecord ) : Boolean;
  2541. var TheReturnString : String;  { Internal string holder }
  2542.     TheResult       : Integer; { Internal int holder    }
  2543. begin
  2544.   Result := true;
  2545.   if PCRPointer^.CStartDir <> '' then
  2546.   begin
  2547.     TheReturnString :=
  2548.      DoCStyleFormat( 'CWD %s' ,
  2549.       [ PCRPointer^.CStartDir ] );
  2550.     { Put result in progress and status line }
  2551.     AddProgressText( TheReturnString );
  2552.     ShowProgressText( TheReturnString );
  2553.     { Send Password sequence }
  2554.     TheResult := PerformFTPCommand( 'CWD %s',
  2555.                                     [ PCRPointer^.CStartDir ] );
  2556.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2557.     begin
  2558.       Result := false;
  2559.       FTPCommandInProgress := false;
  2560.       exit;
  2561.     end;
  2562.     repeat
  2563.       TheResult := GetFTPServerResponse( TheReturnString );
  2564.       { Put result in progress and status line }
  2565.       AddProgressText( TheReturnString );
  2566.       ShowProgressText( TheReturnString );
  2567.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2568.    FTPCommandInProgress := false;
  2569.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2570.     begin
  2571.       { Do clever C formatting trick }
  2572.       TheReturnString :=
  2573.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2574.         [ PCRPointer^.CStartDir ] );
  2575.       { Put result in progress and status line }
  2576.       AddProgressText( TheReturnString );
  2577.       ShowProgressErrorText( TheReturnString );
  2578.       { Signal error }
  2579.       Result := False;
  2580.       { leave }
  2581.       exit;
  2582.     end
  2583.     else Result := true; { Signal no problem }
  2584.   end;
  2585. end;
  2586.  
  2587. { This is the FTP components CWD routine }
  2588. function TFTPComponent.SetRemoteDirectory( TheDir : String ) : Boolean;
  2589. var TheReturnString : String;  { Internal string holder }
  2590.     TheResult       : Integer; { Internal int holder    }
  2591. begin
  2592.   Result := true;
  2593.   if TheDir <> '' then
  2594.   begin
  2595.     TheReturnString :=
  2596.      DoCStyleFormat( 'CWD %s' ,
  2597.       [ TheDir ] );
  2598.     { Put result in progress and status line }
  2599.     AddProgressText( TheReturnString );
  2600.     ShowProgressText( TheReturnString );
  2601.     { Send Password sequence }
  2602.     TheResult := PerformFTPCommand( 'CWD %s',
  2603.                                     [ TheDir ] );
  2604.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2605.     begin
  2606.       Result := false;
  2607.       FTPCommandInProgress := false;
  2608.       exit;
  2609.     end;
  2610.     repeat
  2611.       TheResult := GetFTPServerResponse( TheReturnString );
  2612.       { Put result in progress and status line }
  2613.       AddProgressText( TheReturnString );
  2614.       ShowProgressText( TheReturnString );
  2615.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2616.    FTPCommandInProgress := false;
  2617.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2618.     begin
  2619.       { Do clever C formatting trick }
  2620.       TheReturnString :=
  2621.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2622.         [ TheDir ] );
  2623.       { Put result in progress and status line }
  2624.       AddProgressText( TheReturnString );
  2625.       ShowProgressErrorText( TheReturnString );
  2626.       { Signal error }
  2627.       Result := False;
  2628.       { leave }
  2629.       exit;
  2630.     end
  2631.     else Result := true; { Signal no problem }
  2632.   end;
  2633. end;
  2634.  
  2635. { This is the FTP components QUIT routine }
  2636. function TFTPComponent.Disconnect : Boolean;
  2637. var TheReturnString : String;  { Internal string holder }
  2638.     TheResult       : Integer; { Internal int holder    }
  2639. begin
  2640.   TheReturnString :=
  2641.    DoCStyleFormat( 'QUIT' ,
  2642.     [ nil ] );
  2643.   { Put result in progress and status line }
  2644.   AddProgressText( TheReturnString );
  2645.   ShowProgressText( TheReturnString );
  2646.   { Begin login sequence with user name }
  2647.   PerformFTPCommand( 'QUIT', [ nil ] );
  2648.   repeat
  2649.     TheResult := GetFTPServerResponse( TheReturnString );
  2650.     { Put result in progress and status line }
  2651.     AddProgressText( TheReturnString );
  2652.     ShowProgressText( TheReturnString );
  2653.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2654.   FTPCommandInProgress := false;
  2655.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2656.   begin
  2657.     { Do clever C formatting trick }
  2658.     TheReturnString :=
  2659.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2660.       [ nil ] );
  2661.     { Put result in progress and status line }
  2662.     AddProgressText( TheReturnString );
  2663.     ShowProgressErrorText( TheReturnString );
  2664.     { Signal error }
  2665.     Result := False;
  2666.     { leave }
  2667.     exit;
  2668.   end
  2669.   else Result := true; { Signal no problem }
  2670. end;
  2671.  
  2672. { This is the FTP components PWD routine }
  2673. function TFTPComponent.GetRemoteWorkingDirectory( var RemoteDir : String )
  2674.           : Boolean;
  2675. var TheReturnString : String;  { Internal string holder }
  2676.     TheResult       : Integer; { Internal int holder    }
  2677. begin
  2678.   TheReturnString :=
  2679.    DoCStyleFormat( 'PWD' ,
  2680.     [ nil ] );
  2681.   { Put result in progress and status line }
  2682.   AddProgressText( TheReturnString );
  2683.   ShowProgressText( TheReturnString );
  2684.   { Send Password sequence }
  2685.   TheResult := PerformFTPCommand( 'PWD',
  2686.                                   [ nil ] );
  2687.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2688.   begin
  2689.     Result := false;
  2690.     FTPCommandInProgress := false;
  2691.     exit;
  2692.   end;
  2693.   repeat
  2694.     TheResult := GetFTPServerResponse( TheReturnString );
  2695.     { Put result in progress and status line }
  2696.     AddProgressText( TheReturnString );
  2697.     ShowProgressText( TheReturnString );
  2698.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2699.   FTPCommandInProgress := false;
  2700.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2701.   begin
  2702.     { Do clever C formatting trick }
  2703.     TheReturnString :=
  2704.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2705.       [ nil ] );
  2706.     { Put result in progress and status line }
  2707.     AddProgressText( TheReturnString );
  2708.     ShowProgressErrorText( TheReturnString );
  2709.     { Signal error }
  2710.     Result := False;
  2711.     { leave }
  2712.     exit;
  2713.   end
  2714.   else
  2715.   begin
  2716.     Result := true; { Signal no problem }
  2717.     RemoteDir := TheReturnString; { Send back last string on faith }
  2718.   end;
  2719. end;
  2720.  
  2721. { This function sets up a listening port on socekt 2 and handle text replies }
  2722. function TFTPComponent.GetListeningPort : Integer;
  2723. var
  2724.   Address1 ,
  2725.   Address2 ,
  2726.   Address3 ,
  2727.   Address4        : integer; { Address integer conversions }
  2728.   IPAddress       : string;  { IP Address holder           }
  2729.   PortCommand     : string;  { Command holder              }
  2730.   TheResult       : Integer; { Result holder               }
  2731.   TheReturnString : String;  { ditto                       }
  2732. begin
  2733.   { Set up any port on socket 2 }
  2734.   Socket2.PortName := '0';
  2735.   { Listen on a socket }
  2736.   Socket2.CCSockListen;
  2737.   { Get the IP Address of socket 1 and convert it to numbers }
  2738.   IPAddress := Socket1.GetSocketIPAddress( Socket1.TheSocket );
  2739.   Address1 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2740.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2741.   Address2 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress) -1 ));
  2742.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2743.   Address3 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2744.   Address4 := StrToInt( copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 ));
  2745.   { Turn it into a command and add socket 2 stuff }
  2746.   PortCommand := format( 'PORT %d,%d,%d,%d,%d,%d' ,
  2747.    [ Address1 , Address2 , Address3 , Address4 ,
  2748.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) Shr 8,
  2749.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) and $ff ]);
  2750.   { Put result in progress and status line }
  2751.   AddProgressText( PortCommand + #13#10 );
  2752.   ShowProgressText( PortCommand  + #13#10 );
  2753.   TheResult := PerformFTPCommand( PortCommand , [nil] );
  2754.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2755.   begin
  2756.     Result := TCPIP_STATUS_FATAL_ERROR;
  2757.     FTPCommandInProgress := false;
  2758.     exit;
  2759.   end;
  2760.   repeat
  2761.     TheResult := GetFTPServerResponse( TheReturnString );
  2762.     { Put result in progress and status line }
  2763.     AddProgressText( TheReturnString );
  2764.     ShowProgressText( TheReturnString );
  2765.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2766.   FTPCommandInProgress := false;
  2767.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2768.   begin
  2769.     { Do clever C formatting trick }
  2770.     TheReturnString :=
  2771.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2772.       [ nil ] );
  2773.     { Put result in progress and status line }
  2774.     AddProgressText( TheReturnString );
  2775.     ShowProgressErrorText( TheReturnString );
  2776.     { Signal error }
  2777.     Result := TheResult;
  2778.     { leave }
  2779.     exit;
  2780.   end
  2781.   else
  2782.   begin
  2783.     { Return good result and leave }
  2784.     Result := TheResult;
  2785.     exit;
  2786.   end;
  2787. end;
  2788.  
  2789. { This function returns part of a unit text string }
  2790. function TFTPComponent.GetUNIXTextString( var StringIn : String ) : String;
  2791. var
  2792.   ReturnString : String;
  2793.   TheLength ,
  2794.   Counter_1   : integer;
  2795. begin
  2796.   TheLength := Length( StringIn );
  2797.   if TheLength > 1 then
  2798.   begin
  2799.     for Counter_1 := 1 to TheLength do
  2800.     begin
  2801.       if StringIn[ Counter_1 ] = #10 then
  2802.       begin
  2803.         ReturnString := HolderLine;
  2804.         HolderLine := '';
  2805.         StringIn := Copy( StringIn , Counter_1 + 1 , 255 );
  2806.         Result := ReturnString;
  2807.         exit;
  2808.       end
  2809.       else
  2810.       begin
  2811.         if StringIn[ Counter_1 ] <> #0 then
  2812.         begin
  2813.           if StringIn[ Counter_1 ] <> #13 then
  2814.            HolderLine := HolderLine + StringIn[ Counter_1 ];
  2815.         end
  2816.         else
  2817.         begin
  2818.           Result := '';
  2819.           StringIn := '';
  2820.         end;
  2821.       end;
  2822.     end;
  2823.   end;
  2824.   Result := '';
  2825.   StringIn := '';
  2826. end;
  2827.  
  2828. procedure TFTPComponent.GetFileNameFromUNIXFileName( var TheName : String );
  2829. var Counter_1 : Integer;
  2830.     ResultString : String;
  2831.     Finished : Boolean;
  2832. begin
  2833.   if Pos( 'TOTAL' , Uppercase( TheName )) <> 0 then
  2834.   begin
  2835.     TheName := '';
  2836.     exit;
  2837.   end;
  2838.   Counter_1 := Length( TheName );
  2839.   ResultString := '';
  2840.   Finished := false;
  2841.   while not Finished do
  2842.   begin
  2843.     if TheName[ Counter_1 ] <> ' ' then
  2844.     begin
  2845.       Counter_1 := Counter_1 - 1;
  2846.       if Counter_1 = 0 then
  2847.       begin
  2848.         ResultString := TheName;
  2849.         Finished := true;
  2850.       end;
  2851.     end
  2852.     else
  2853.     begin
  2854.       Finished := true;
  2855.       ResultString := Copy( TheName , Counter_1 + 1 , 255 );
  2856.     end;
  2857.   end;
  2858.   TheName := ResultString;
  2859. end;
  2860.  
  2861. { This is the FTP components get remote directory listing into a list box }
  2862. function TFTPComponent.GetRemoteDirectoryListing( TheListBox : TListBox )
  2863.           : Boolean;
  2864. var TheReturnString : String;  { Internal string holder }
  2865.     TheResult       : Integer; { Internal int holder    }
  2866.     InputString     : String;
  2867.     Through ,
  2868.     Finished        : Boolean;
  2869. begin
  2870.   TheListBox.Clear;
  2871.   TheListbox.Tag := 2;
  2872.   TheListBox.Items.Add('..');
  2873.   Result := true;
  2874.   TheReturnString :=
  2875.    DoCStyleFormat( 'TYPE A' ,
  2876.     [ nil ] );
  2877.   { Put result in progress and status line }
  2878.   AddProgressText( TheReturnString );
  2879.   ShowProgressText( TheReturnString );
  2880.   { Send Password sequence }
  2881.   TheResult := PerformFTPCommand( 'TYPE A',
  2882.                                   [ nil ] );
  2883.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2884.   begin
  2885.     Result := true;
  2886.     FTPCommandInProgress := false;
  2887.     exit;
  2888.   end;
  2889.   repeat
  2890.     TheResult := GetFTPServerResponse( TheReturnString );
  2891.     { Put result in progress and status line }
  2892.     AddProgressText( TheReturnString );
  2893.     ShowProgressText( TheReturnString );
  2894.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2895.   FTPCommandInProgress := false;
  2896.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2897.   begin
  2898.     { Do clever C formatting trick }
  2899.     TheReturnString :=
  2900.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2901.       [ nil ] );
  2902.     { Put result in progress and status line }
  2903.     AddProgressText( TheReturnString );
  2904.     ShowProgressErrorText( TheReturnString );
  2905.     { Signal error }
  2906.     Result := true;
  2907.     { leave }
  2908.     exit;
  2909.   end
  2910.   else
  2911.   begin
  2912.     { Set up socket 2 for listening }
  2913.     Socket2.AsynchMode := False;
  2914.     Socket2.NonAsynchTimeoutValue := 60;
  2915.     { do a listen and send command to server that this is receipt socket }
  2916.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2917.     begin
  2918.       Socket2.CCSockCancelListen;
  2919.       exit;
  2920.     end;
  2921.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2922.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  2923.     GetFTPServerResponse( TheReturnString );
  2924.     AddProgressText( TheReturnString );
  2925.     ShowProgressText( TheReturnString );
  2926.     Socket1.NonAsynchTimeoutValue := 30;
  2927.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2928.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2929.     begin
  2930.       TheReturnString :=
  2931.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  2932.         [ nil ] );
  2933.       { Put result in progress and status line }
  2934.       AddProgressText( TheReturnString );
  2935.       ShowProgressErrorText( TheReturnString );
  2936.       Socket2.CCSockCancelListen;
  2937.       Result := true;
  2938.       exit;
  2939.     end;
  2940.     Socket2.CCSockAccept;
  2941.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2942.     begin
  2943.       TheReturnString :=
  2944.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2945.         [ nil ] );
  2946.       { Put result in progress and status line }
  2947.       AddProgressText( TheReturnString );
  2948.       ShowProgressErrorText( TheReturnString );
  2949.       Result := true;
  2950.       exit;
  2951.     end;
  2952.     Through := false;
  2953.     repeat
  2954.       TheReturnString := Socket2.StringData;
  2955.       if Length( TheReturnString ) = 0 then Through := true;
  2956.       if Length( TheReturnString ) > 0 then
  2957.       begin
  2958.         finished := false;
  2959.         while not finished do
  2960.         begin
  2961.           InputString := GetUNIXTextString( TheReturnString );
  2962.           if InputString = '' then Finished := true else
  2963.           begin
  2964.             GetFileNameFromUNIXFileName( InputString);
  2965.             If InputString <> '' then
  2966.             TheListBox.Items.Add( InputString );
  2967.           end;
  2968.         end;
  2969.       end;
  2970.       if GlobalAbortedFlag then
  2971.       begin
  2972.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2973.         repeat
  2974.           TheResult := GetFTPServerResponse( TheReturnString );
  2975.           { Put result in progress and status line }
  2976.           AddProgressText( TheReturnString );
  2977.           ShowProgressText( TheReturnString );
  2978.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2979.         result := true;
  2980.         exit;
  2981.       end;
  2982.     until Through;
  2983.     GetFTPServerResponse( TheReturnString );
  2984.     AddProgressText( TheReturnString );
  2985.     ShowProgressText( TheReturnString );
  2986.     { cancel listening on second socket and close it }
  2987.     Socket2.CCSockCancelListen;
  2988.     Socket2.CCSockClose;
  2989.   end;
  2990.   FTPCommandInProgress := false;
  2991. end;
  2992.  
  2993. { This is the FTP components get remote directory listing into a list box }
  2994. function TFTPComponent.GetRemoteDirectoryListingToMemo : Boolean;
  2995. var TheReturnString : String;  { Internal string holder }
  2996.     TheResult       : Integer; { Internal int holder    }
  2997.     Through         : Boolean;
  2998. begin
  2999.   Result := true;
  3000.   TheReturnString :=
  3001.    DoCStyleFormat( 'TYPE A' ,
  3002.     [ nil ] );
  3003.   { Put result in progress and status line }
  3004.   AddProgressText( TheReturnString );
  3005.   ShowProgressText( TheReturnString );
  3006.   { Send Password sequence }
  3007.   TheResult := PerformFTPCommand( 'TYPE A',
  3008.                                   [ nil ] );
  3009.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  3010.   begin
  3011.     Result := true;
  3012.     FTPCommandInProgress := false;
  3013.     exit;
  3014.   end;
  3015.   repeat
  3016.     TheResult := GetFTPServerResponse( TheReturnString );
  3017.     { Put result in progress and status line }
  3018.     AddProgressText( TheReturnString );
  3019.     ShowProgressText( TheReturnString );
  3020.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3021.   FTPCommandInProgress := false;
  3022.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  3023.   begin
  3024.     { Do clever C formatting trick }
  3025.     TheReturnString :=
  3026.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  3027.       [ nil ] );
  3028.     { Put result in progress and status line }
  3029.     AddProgressText( TheReturnString );
  3030.     ShowProgressErrorText( TheReturnString );
  3031.     { Signal error }
  3032.     Result := true;
  3033.     { leave }
  3034.     exit;
  3035.   end
  3036.   else
  3037.   begin
  3038.     { Set up socket 2 for listening }
  3039.     Socket2.AsynchMode := False;
  3040.     Socket2.NonAsynchTimeoutValue := 30;
  3041.     { do a listen and send command to server that this is receipt socket }
  3042.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  3043.     begin
  3044.       Socket2.CCSockCancelListen;
  3045.       exit;
  3046.     end;
  3047.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  3048.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  3049.     GetFTPServerResponse( TheReturnString );
  3050.     AddProgressText( TheReturnString );
  3051.     ShowProgressText( TheReturnString );
  3052.     Socket1.NonAsynchTimeoutValue := 30;
  3053.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  3054.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  3055.     begin
  3056.       TheReturnString :=
  3057.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  3058.         [ nil ] );
  3059.       { Put result in progress and status line }
  3060.       AddProgressText( TheReturnString );
  3061.       ShowProgressErrorText( TheReturnString );
  3062.       Socket2.CCSockCancelListen;
  3063.       Result := true;
  3064.       exit;
  3065.     end;
  3066.     Socket2.CCSockAccept;
  3067.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  3068.     begin
  3069.       TheReturnString :=
  3070.        DoCStyleFormat( 'Could not establish receive socket!' ,
  3071.         [ nil ] );
  3072.       { Put result in progress and status line }
  3073.       AddProgressText( TheReturnString );
  3074.       ShowProgressErrorText( TheReturnString );
  3075.       Result := true;
  3076.       exit;
  3077.     end;
  3078.     Through := false;
  3079.     repeat
  3080.       TheReturnString := Socket2.StringData;
  3081.       if Length( TheReturnString ) = 0 then Through := true;
  3082.       if Length( TheReturnString ) > 0 then
  3083.       begin
  3084.         { Put result in progress and status line }
  3085.         AddProgressText( TheReturnString );
  3086.         ShowProgressText( TheReturnString );
  3087.       end;
  3088.       if GlobalAbortedFlag then
  3089.       begin
  3090.         Socket1.OutOfBand := 'ABOR'+#13#10;
  3091.         repeat
  3092.           TheResult := GetFTPServerResponse( TheReturnString );
  3093.           { Put result in progress and status line }
  3094.           AddProgressText( TheReturnString );
  3095.           ShowProgressText( TheReturnString );
  3096.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3097.         result := true;
  3098.         exit;
  3099.       end;
  3100.     until Through;
  3101.     GetFTPServerResponse( TheReturnString );
  3102.     AddProgressText( TheReturnString );
  3103.     ShowProgressText( TheReturnString );
  3104.     { cancel listening on second socket and close it }
  3105.     Socket2.CCSockCancelListen;
  3106.     Socket2.CCSockClose;
  3107.   end;
  3108. end;
  3109.  
  3110. { This is the FTP components get local directory listing into a list box }
  3111. function TFTPComponent.GetLocalDirectoryAndListing( var TheString : String;
  3112.                                                         TheListBox : TListBox )
  3113.           : Boolean;
  3114. var TheFLB : TFileListBox;
  3115. begin
  3116.   { Get the working directory }
  3117.   GetDir( 0 , TheString );
  3118.   { Clear incoming LB }
  3119.   TheListBox.Clear;
  3120.   TheListBox.Tag := 2;
  3121.   TheFLB := TFileListBox.Create( Application.MainForm );
  3122.   TheFLB.Visible := false;
  3123.   TheFLB.Parent := Application.MainForm;
  3124.   TheFLB.FileType := [ ftNormal , ftDirectory ];
  3125.   TheFLB.Directory := TheString;
  3126.   TheFLB.Update;
  3127.   TheListBox.Items.Assign( TheFLB.Items );
  3128.   TheFLB.Free;
  3129.   result := true;
  3130. end;
  3131.  
  3132. { This is a clever c-style formatting trick }
  3133. function TFTPComponent.DoCStyleFormat(
  3134.                 TheText      : string;
  3135.           const TheArguments : array of const ) : String;
  3136. begin
  3137.   Result := Format( TheText , TheArguments ) + #13#10;
  3138. end;
  3139.  
  3140. function TFTPComponent.GetQuotedString( TheString : String ) : String;
  3141. var TheIndex     : Integer; { Holder var }
  3142.     ResultString : String;  { ditto      }
  3143. begin
  3144.   { Find out if " present at all }
  3145.   TheIndex := Pos( '"' , TheString );
  3146.   If TheIndex = 0 then
  3147.   begin
  3148.     { If not, return null string and exit }
  3149.     Result := '';
  3150.     exit;
  3151.   end
  3152.   else
  3153.   begin
  3154.     { Get from first " to end of string in holder }
  3155.     ResultString := Copy( TheString , TheIndex + 1 , 255 );
  3156.     { Find position to second " }
  3157.     TheIndex := Pos( '"' , ResultString );
  3158.     { If no ending " then return whole string and leave }
  3159.     if TheIndex = 0 then
  3160.     begin
  3161.       Result := ResultString;
  3162.       exit;
  3163.     end
  3164.     else
  3165.     begin
  3166.       { Get internal text between quotes and exit }
  3167.       ResultString := Copy( ResultString , 1 , TheIndex - 1 );
  3168.       Result := ResultString;
  3169.     end;
  3170.   end;
  3171. end;
  3172.  
  3173. procedure TCCINetCCForm.UpdateGauge( BytesFinished , TotalToHandle : longint );
  3174. var
  3175.   Percentage : longint;
  3176. begin
  3177.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3178.   if TotalToHandle = 0 then exit;
  3179.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3180.   Gauge1.Progress := Percentage;
  3181.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3182.    ' bytes ' + FileNameToXFer + ' (' + IntToStr( Percentage ) + '% Done)';
  3183. end;
  3184.  
  3185. procedure TCCINetCCForm.UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  3186. var
  3187.   Percentage : longint;
  3188. begin
  3189.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3190.   if TotalToHandle = 0 then exit;
  3191.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3192.   Gauge1.Progress := Percentage;
  3193.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3194.    ' bytes mail (' + IntToStr( Percentage ) + '% Done)';
  3195. end;
  3196.  
  3197. procedure TCCINetCCForm.UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  3198. var
  3199.   Percentage : longint;
  3200. begin
  3201.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3202.   if TotalToHandle = 0 then exit;
  3203.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3204.   Gauge1.Progress := Percentage;
  3205.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3206.    ' bytes UUCode (' + IntToStr( Percentage ) + '% Done)';
  3207.   Panel1.Show;
  3208. end;
  3209.  
  3210. { This procedure actually attempts to connect to the internet at an ftp site }
  3211. function TCCINetCCForm.DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3212. var TheReturnString : String; { Display results of connection in status lines }
  3213. begin
  3214.   { Create the component }
  3215.   Result := false;
  3216.   { Do busy cursors }
  3217.   SetHGCursors;
  3218.   if not TheFTPComponent.EstablishConnection( PCRPointer ) then
  3219.   begin
  3220.     { Do saved cursors }
  3221.     TheFTPComponent.FTPCommandInProgress := false;
  3222.     TheFTPComponent.Connection_Established := false;
  3223.     SetNormalCursors;
  3224.     exit;
  3225.   end
  3226.   else
  3227.   begin { Connected; continue login process }
  3228.     if not TheFTPComponent.LoginUser( PCRPointer ) then
  3229.     begin
  3230.       { Do saved cursors }
  3231.       TheFTPComponent.FTPCommandInProgress := false;
  3232.       TheFTPComponent.Connection_Established := false;
  3233.       SetNormalCursors;
  3234.       exit;
  3235.     end;
  3236.     if not TheFTPComponent.SendPassword( PCRPointer ) then
  3237.     begin
  3238.       { Do saved cursors }
  3239.       TheFTPComponent.FTPCommandInProgress := false;
  3240.       TheFTPComponent.Connection_Established := false;
  3241.       SetNormalCursors;
  3242.       exit;
  3243.     end;
  3244.     if not TheFTPComponent.SetRemoteStartupDirectory( PCRPointer ) then
  3245.     begin
  3246.       { Do saved cursors }
  3247.       SetNormalCursors;
  3248.       TheFTPComponent.Connection_Established := false;
  3249.       TheFTPComponent.FTPCommandInProgress := false;
  3250.       exit;
  3251.     end;
  3252.     if not TheFTPComponent.GetRemoteWorkingDirectory( TheReturnString ) then
  3253.     begin
  3254.       { Do saved cursors }
  3255.       TheFTPComponent.Connection_Established := false;
  3256.       TheFTPComponent.FTPCommandInProgress := false;
  3257.       SetNormalCursors;
  3258.       exit;
  3259.     end;
  3260.     { Put up remote directory via PWD and strip quotes }
  3261.     Label4.Caption := TheFTPComponent.GetQuotedString( TheReturnString );
  3262.     { Get the listings of directories and exit OK }
  3263.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  3264.     TheFTPComponent.GetLocalDirectoryAndListing( TheReturnString ,
  3265.      Listbox2 );
  3266.     if Label5.Canvas.TextWidth( TheReturnString ) > Label5.Width then
  3267.      TheReturnString := TheFTPComponent.GetShortPathName( TheReturnString );
  3268.     Label5.Caption := TheReturnString;
  3269.     SetNormalCursors;
  3270.     Result := true;
  3271.     EnableFTPMenus;
  3272.     TheFTPComponent.FTPCommandInProgress := false;
  3273.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3274.   end;
  3275. end;
  3276.  
  3277. { This procedure actually attempts to connect to the internet at an nntp site }
  3278. function TCCINetCCForm.DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3279. begin
  3280.   { Create the component }
  3281.   Result := false;
  3282.   { Do busy cursors }
  3283.   SetHGCursors;
  3284.   if not TheNNTPComponent.EstablishConnection( PCRPointer ) then
  3285.   begin
  3286.     { Do saved cursors }
  3287.     TheNNTPComponent.NNTPCommandInProgress := false;
  3288.     TheNNTPComponent.Connection_Established := false;
  3289.     SetNormalCursors;
  3290.     exit;
  3291.   end
  3292.   else
  3293.   begin { Connected; continue login process }
  3294.     SetNormalCursors;
  3295.     Result := true;
  3296.     EnableNNTPMenus;
  3297.     TheNNTPComponent.NNTPCommandInProgress := false;
  3298.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3299.   end;
  3300. end;
  3301.  
  3302. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3303. procedure TCCINetCCForm.DoFTPDisconnect;
  3304. begin
  3305.   { Call QUIT command }
  3306.   TheFTPComponent.Disconnect;
  3307.   { Kill the socket }
  3308.   TheFTPComponent.Socket1.CCSockClose;
  3309. end;
  3310.  
  3311. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3312. procedure TCCINetCCForm.DoNNTPDisconnect;
  3313. begin
  3314.   { Call QUIT command }
  3315.   TheNNTPComponent.Disconnect;
  3316.   { Kill the socket }
  3317.   TheNNTPComponent.Socket1.CCSockClose;
  3318. end;
  3319.  
  3320. { This procedure reads in the ini file and default path info }
  3321. procedure TCCINetCCForm.ReadIniData;
  3322. begin
  3323.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3324.   MailPath := TheICCIniFile.ReadString( 'Paths','MailPath','C:\WINDOWS' );
  3325.   NewsPath := TheICCIniFile.ReadString( 'Paths','NewsPath','C:\WINDOWS' );
  3326.   FTPPath := TheICCIniFile.ReadString( 'Paths','FTPPath','C:\WINDOWS' );
  3327.   PasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','PWControl',2 );
  3328.   DefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','DefDL', 3 );
  3329.   TheAnonRedialVector := TheICCIniFile.ReadInteger( 'Vectors','AnonRD', 20 );
  3330.   NewsReadArticlePurgingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsPurge', 1 );
  3331.   NewsPostQueueingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsQueue', 1 );
  3332.   NewsReadArticleDisplayVector := TheICCIniFile.ReadInteger( 'Vectors','NewsRDisp', 1 );
  3333.   NewsUUMIMEVector := TheICCIniFile.ReadInteger( 'Vectors','NewsUUMIME', 2 );
  3334.   NewsInitialUpdateVector := TheICCIniFile.ReadInteger( 'Vectors','NewsInitUD', 1 );
  3335.   EMPasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','EMPWControl', 1 );
  3336.   EMRemoteDeletionVector  := TheICCIniFile.ReadInteger( 'Vectors','EMRemDel', 2 );
  3337.   EMChokeVector           := TheICCIniFile.ReadInteger( 'Vectors','EMChoke', 1 );
  3338.   EMDefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','EMInitUD', 1 );
  3339.   EMQueueVector           := TheICCIniFile.ReadInteger( 'Vectors','EMQueue', 1 );
  3340.   TheICCIniFile.Free;
  3341. end;
  3342.  
  3343. { This procedure writes out default path data to the ini file }
  3344. procedure TCCINetCCForm.WriteIniData;
  3345. begin
  3346.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3347.   TheICCIniFile.WriteString( 'Paths','MailPath', MailPath );
  3348.   TheICCIniFile.WriteString( 'Paths','NewsPath', NewsPath );
  3349.   TheICCIniFile.WriteString( 'Paths','FTPPath', FTPPath );
  3350.   TheICCIniFile.WriteInteger( 'Vectors','PWControl', PasswordControlVector );
  3351.   TheICCIniFile.WriteInteger( 'Vectors','DefDL', DefaultDownloadVector );
  3352.   TheICCIniFile.WriteInteger( 'Vectors','AnonRD', TheAnonRedialVector );
  3353.   TheICCIniFile.WriteInteger( 'Vectors','NewsPurge',
  3354.    NewsReadArticlePurgingVector );
  3355.   TheICCIniFile.WriteInteger( 'Vectors','NewsQueue', NewsPostQueueingVector );
  3356.   TheICCIniFile.WriteInteger( 'Vectors','NewsRDisp',
  3357.    NewsReadArticleDisplayVector );
  3358.   TheICCIniFile.WriteInteger( 'Vectors','NewsUUMIME', NewsUUMIMEVector );
  3359.   TheICCIniFile.WriteInteger( 'Vectors','NewsInitUD', NewsInitialUpdateVector );
  3360.   TheICCIniFile.WriteInteger( 'Vectors','EMPWControl', EMPasswordControlVector );
  3361.   TheICCIniFile.WriteInteger( 'Vectors','EMRemDel', EMRemoteDeletionVector );
  3362.   TheICCIniFile.WriteInteger( 'Vectors','EMChoke', EMChokeVector );
  3363.   TheICCIniFile.WriteInteger( 'Vectors','EMInitUD', EMDefaultDownloadVector );
  3364.   TheICCIniFile.WriteInteger( 'Vectors','EMQueue', EMQueueVector );
  3365.   TheICCIniFile.Free;
  3366. end;
  3367.  
  3368. { Procedure to load the FTP Site list }
  3369. procedure TCCINetCCForm.LoadFTPSiteFile;
  3370. var TheTCRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3371.     FTPSLName   : String;             { FTP Site List filename }
  3372.     Counter_1   : Integer;            { Loop counter           }
  3373. begin
  3374.   { Create the sites list list }
  3375.   TheFTPSiteList := TList.Create;
  3376.   { Set up the FTP sites list file name }
  3377.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3378.   { If the FTP Site List exists load it in }
  3379.   if FileExists( FTPSLName ) then
  3380.   begin
  3381.     { set up the file and open it }
  3382.     AssignFile( TheFTPSiteFile , FTPSLName );
  3383.     Reset( TheFTPSiteFile );
  3384.     { read in the records }
  3385.     for Counter_1 := 0 to FileSize( TheFTPSiteFile ) - 1 do
  3386.     begin
  3387.       { Create the TCRecord }
  3388.       New( TheTCRecord );
  3389.       { Read in the data record }
  3390.       Seek( TheFTPSiteFile , Counter_1 );
  3391.       Read( TheFTPSiteFile , TheTCRecord^ );
  3392.       { Add the record to the list }
  3393.       TheFTPSiteList.Add( TheTCRecord );
  3394.     end;
  3395.     { close the file }
  3396.     CloseFile( TheFTPSiteFile );
  3397.   end
  3398.   else
  3399.   { Otherwise create a default one with a few anonymous sites }
  3400.   begin
  3401.     { create new record }
  3402.     New( TheTCRecord );
  3403.     { fill in its info }
  3404.     with TheTCRecord^ do
  3405.     begin
  3406.       CProfile   := 'Winsite Windows Archive';
  3407.       CIPAddress := 'ftp.winsite.com';
  3408.       CUserName  := 'anonymous';
  3409.       CPassword  := 'guest@nowhere.com';
  3410.       CStartDir  := '/pub';
  3411.     end;
  3412.     { add it to the list }
  3413.     { do it three more times }
  3414.     TheFTPSiteList.Add( TheTCRecord );
  3415.     New( TheTCRecord );
  3416.     with TheTCRecord^ do
  3417.     begin
  3418.       CProfile   := 'Digital Equipment Corp';
  3419.       CIPAddress := 'gatekeeper.dec.com';
  3420.       CUserName  := 'anonymous';
  3421.       CPassword  := 'guest@nowhere.com';
  3422.       CStartDir  := '/pub';
  3423.     end;
  3424.     TheFTPSiteList.Add( TheTCRecord );
  3425.     New( TheTCRecord );
  3426.     with TheTCRecord^ do
  3427.     begin
  3428.       CProfile   := 'Microsoft FTP Site';
  3429.       CIPAddress := 'ftp.microsoft.com';
  3430.       CUserName  := 'anonymous';
  3431.       CPassword  := 'guest@nowhere.com';
  3432.       CStartDir  := '/pub';
  3433.     end;
  3434.     TheFTPSiteList.Add( TheTCRecord );
  3435.     New( TheTCRecord );
  3436.     with TheTCRecord^ do
  3437.     begin
  3438.       CProfile   := 'Oakland MSDOS Archive';
  3439.       CIPAddress := 'oak.oakland.edu';
  3440.       CUserName  := 'anonymous';
  3441.       CPassword  := 'guest@nowhere.com';
  3442.       CStartDir  := '/pub';
  3443.     end;
  3444.     TheFTPSiteList.Add( TheTCRecord );
  3445.     { create the file and write out the data, then close it }
  3446.     AssignFile( TheFTPSiteFile , FTPSLName );
  3447.     Rewrite( TheFTPSiteFile );
  3448.     for Counter_1 := 0 to 3 do
  3449.     begin
  3450.       TheTCRecord :=
  3451.        PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3452.       Seek( TheFTPSiteFile , Counter_1 );
  3453.       Write( TheFTPSiteFile , TheTCRecord^ );
  3454.     end;
  3455.     CloseFile( TheFTPSiteFile );
  3456.   end;
  3457.   { Create the working copy for use to make safe changes in info dlg }
  3458.   TheWorkingFTPSL := TList.Create;
  3459.   For Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3460.   begin
  3461.     New( TheTCRecord );
  3462.     TheTCRecord^ := PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  3463.     TheWorkingFTPSL.Add( TheTCRecord );
  3464.   end;
  3465. end;
  3466.  
  3467. { Procedure to load the NNTP Site list }
  3468. procedure TCCINetCCForm.LoadNNTPSiteFile;
  3469. var TheNGRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3470.     NNTPSLName  : String;             { NNTP Site List filename }
  3471.     Counter_1   : Integer;            { Loop counter           }
  3472. begin
  3473.   { Create the sites list list }
  3474.   TheNewsServerList := TList.Create;
  3475.   { Set up the FTP sites list file name }
  3476.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3477.   { If the FTP Site List exists load it in }
  3478.   if FileExists( NNTPSLName ) then
  3479.   begin
  3480.     { set up the file and open it }
  3481.     AssignFile( TheNewsServerFile , NNTPSLName );
  3482.     Reset( TheNewsServerFile );
  3483.     { read in the records }
  3484.     for Counter_1 := 0 to FileSize( TheNewsServerFile ) - 1 do
  3485.     begin
  3486.       { Create the TCRecord }
  3487.       New( TheNGRecord );
  3488.       { Read in the data record }
  3489.       Seek( TheNewsServerFile , Counter_1 );
  3490.       Read( TheNewsServerFile , TheNGRecord^ );
  3491.       { Add the record to the list }
  3492.       TheNewsServerList.Add( TheNGRecord );
  3493.     end;
  3494.     { close the file }
  3495.     CloseFile( TheNewsServerFile );
  3496.   end
  3497.   else
  3498.   { Otherwise create a default one with a generic news site (?) }
  3499.   begin
  3500.     { create new record }
  3501.     New( TheNGRecord );
  3502.     { fill in its info }
  3503.     with TheNGRecord^ do
  3504.     begin
  3505.       CProfile   := 'My News Server';
  3506.       CIPAddress := 'news.myprovider.com';
  3507.       CUserName  := '';
  3508.       CPassword  := '';
  3509.       CStartDir  := '';
  3510.     end;
  3511.     { add it to the list }
  3512.     { do it three more times }
  3513.     TheNewsServerList.Add( TheNGRecord );
  3514.     { create the file and write out the data, then close it }
  3515.     AssignFile( TheNewsServerFile , NNTPSLName );
  3516.     Rewrite( TheNewsServerFile );
  3517.     TheNGRecord :=
  3518.        PConnectionsRecord( TheNewsServerList.Items[ 0 ] );
  3519.       Seek( TheNewsServerFile , 0 );
  3520.       Write( TheNewsServerFile , TheNGRecord^ );
  3521.     CloseFile( TheNewsServerFile );
  3522.   end;
  3523.   TheWorkingNSSL := TList.Create;
  3524.   For Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3525.   begin
  3526.     New( TheNGRecord );
  3527.     TheNGRecord^ := PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] )^;
  3528.     TheWorkingNSSL.Add( TheNGRecord );
  3529.   end;
  3530. end;
  3531.  
  3532. { This procedure saves off the FTP Site List }
  3533. procedure TCCINetCCForm.SaveFTPSiteFile;
  3534. var TheTCRecord : PConnectionsRecord; { The TC Record pointer  }
  3535.     FTPSLName   : String;             { FTP Site List filename }
  3536.     Counter_1   : Integer;            { Loop counter           }
  3537. begin
  3538.   { Set up the file name }
  3539.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3540.   { Assign the file }
  3541.   AssignFile( TheFTPSiteFile , FTPSLName );
  3542.   { Rewrite it }
  3543.   Rewrite( TheFTPSiteFile );
  3544.   { run the list through the procedure }
  3545.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3546.   begin
  3547.     { get the record from the list }
  3548.     TheTCRecord :=
  3549.      PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3550.     { Do the seek/write }
  3551.     Seek( TheFTPSiteFile , Counter_1 );
  3552.     Write( TheFTPSiteFile , TheTCRecord^ );
  3553.     { free the record }
  3554.     Dispose( TheTCRecord );
  3555.   end;
  3556.   { Close the file }
  3557.   CloseFile( TheFTPSiteFile );
  3558.   { Free the list pointers }
  3559.   TheFTPSiteList.Free;
  3560.   TheWorkingFTPSL.Free;
  3561. end;
  3562.  
  3563. { This procedure saves off the FTP Site List }
  3564. procedure TCCINetCCForm.SaveNNTPSiteFile;
  3565. var TheNGRecord : PConnectionsRecord; { The TC Record pointer   }
  3566.     NNTPSLName   : String;            { NNTP Site List filename }
  3567.     Counter_1   : Integer;            { Loop counter           }
  3568. begin
  3569.   { Set up the file name }
  3570.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3571.   { Assign the file }
  3572.   AssignFile( TheNewsServerFile , NNTPSLName );
  3573.   { Rewrite it }
  3574.   Rewrite( TheNewsServerFile );
  3575.   { run the list through the procedure }
  3576.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3577.   begin
  3578.     { get the record from the list }
  3579.     TheNGRecord :=
  3580.      PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] );
  3581.     { Do the seek/write }
  3582.     Seek( TheNewsServerFile , Counter_1 );
  3583.     Write( TheNewsServerFile , TheNGRecord^ );
  3584.     { free the record }
  3585.     Dispose( TheNGRecord );
  3586.   end;
  3587.   { Close the file }
  3588.   CloseFile( TheNewsServerFile );
  3589.   { Free the list pointers }
  3590.   TheNewsServerList.Free;
  3591.   TheWorkingNSSL.Free;
  3592. end;
  3593.  
  3594. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3595. procedure TCCINetCCForm.SetupFTPSiteLists;
  3596. var Counter_1  : Integer;            { Loop counter        }
  3597. begin
  3598.   { Set up display for main form }
  3599.   CCINetCCForm.Tag := 2;
  3600.   CCINetCCForm.Caption := 'CC Internet Command Center -- FTP Mode';
  3601.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3602.   CCINetCCForm.FTP1.Enabled := false;
  3603.   CCINetCCForm.FTP2.Enabled := true;
  3604.   CCINetCCForm.Label1.Caption := 'FTP Site:';
  3605.   CCINetCCForm.Button1.Caption := 'Connect';
  3606.   CCINetCCForm.Label4.Caption := 'Local Dir';
  3607.   CCINetCCForm.Label5.Caption := 'Remote Dir';
  3608.   { Set tag for FTP stuff }
  3609.   CCICInfoDlg.Tag := 2;
  3610.   { set up caption of main label }
  3611.   CCICInfoDlg.Label2.Caption := 'FTP Sites';
  3612.   { hide outline panel }
  3613.   CCICInfoDlg.Panel6.Visible := false;
  3614.   { clear the list box }
  3615.   CCICInfoDlg.ListBox2.Clear;
  3616.   CCINetCCForm.ComboBox1.Clear;
  3617.   { add profile strings to the list box }
  3618.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3619.   begin
  3620.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3621.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3622.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3623.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3624.   end;
  3625.   { Set up caption of special button }
  3626.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  3627.   { Start with top record }
  3628.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3629.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3630.   { put in data from top record and reset captions }
  3631.   with PConnectionsRecord( TheFTPSiteList.Items[ 0 ] )^ do
  3632.   begin
  3633.     with CCICInfoDlg do
  3634.     begin
  3635.       Edit1.Text := CProfile;
  3636.       Panel2.Caption := '            Name:';
  3637.       Edit2.Text := CIPAddress;
  3638.       Panel3.Caption := '     IP Address:';
  3639.       Edit3.Text := CUserName;
  3640.       Panel5.Caption := '    User Name:';
  3641.       case PasswordControlVector of
  3642.         1 : Edit4.Text := CPassword;
  3643.         2 : Edit4.Text := '**********';
  3644.       end;
  3645.       Panel8.Caption := '      Password:';
  3646.       Edit5.Text := CStartDir;
  3647.       Panel9.Caption := '    Starting Dir:';
  3648.     end;
  3649.   end;
  3650. end;
  3651.  
  3652. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3653. procedure TCCINetCCForm.SetupNNTPSiteLists;
  3654. begin
  3655.   { Set up display for main form }
  3656.   CCINetCCForm.Tag := 4; { Usenet News Tag }
  3657.   CCINetCCForm.Caption := 'CC Internet Command Center -- Usenet News Mode';
  3658.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3659.   CCINetCCForm.FTP1.Enabled := true;
  3660.   CCINetCCForm.FTP2.Enabled := false;
  3661.   CCINetCCForm.UsenetNws1.Enabled := false;
  3662.   CCINetCCForm.News1.Enabled := true;
  3663.   CCINetCCForm.Label1.Caption := 'NNTP Server:';
  3664.   CCINetCCForm.Button1.Caption := 'Connect';
  3665.   CCINetCCForm.Label4.Caption := 'SubScribed Groups';
  3666.   CCINetCCForm.Label5.Caption := 'Unread Articles';
  3667.   { Create the working copy for use to make safe changes in info dlg }
  3668. end;
  3669.  
  3670. { This method saves off the Newsgroup and Article Lists }
  3671. procedure TCCINetCCForm.SaveNNTPNewsGroupLists;
  3672. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3673.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3674.     WorkingList : TList;
  3675.     Counter_1 ,
  3676.     Counter_2   : Integer;          { Loop counter              }
  3677.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3678.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3679. begin
  3680.   { Abort if no server to select }
  3681.   if ComboBox1.ItemIndex = -1 then exit;
  3682.   { Get number of server in list }
  3683.   WhichServer := ComboBox1.ItemIndex;
  3684.   { Set up the FTP sites list file name }
  3685.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3686.   { If the FTP Site List exists load it in }
  3687.   { set up the file and open it }
  3688.   AssignFile( TheNewsRCFile , NNTPNGLName );
  3689.   ReWrite( TheNewsRCFile );
  3690.   { read in the records }
  3691.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3692.   begin
  3693.     { Create the TCRecord }
  3694.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3695.     { Read in the data record }
  3696.     Seek( TheNewsRCFile , Counter_1 );
  3697.     Write( TheNewsRCFile , TheNGRecord^ );
  3698.     { Add the record to the list }
  3699.     WorkingList := TList( TheNGRecord^.GLTag );
  3700.     if WorkingList.Count > 0 then
  3701.     begin
  3702.       NNTPARName := TheNGRecord^.GFileName;
  3703.       TheNGArticlesList := TList.Create;
  3704.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3705.       ReWrite( TheNewsArticleFile );
  3706.       for Counter_2 := 0 to WorkingList.Count - 1 do
  3707.       begin
  3708.         TheNGARecord :=
  3709.          PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  3710.         Seek( TheNewsArticleFile , Counter_2 );
  3711.         Write( TheNewsArticleFile , TheNGARecord^ );
  3712.         Dispose( TheNGARecord );
  3713.       end;
  3714.       CloseFile( TheNewsArticleFile );
  3715.     end;
  3716.     WorkingList.Free;
  3717.     Dispose( TheNGRecord );
  3718.   end;
  3719.   { close the file }
  3720.   CloseFile( TheNewsRCFile );
  3721.   { Free the list itself }
  3722.   TheNewsRCList.Free;
  3723. end;
  3724.  
  3725. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3726. procedure TCCINetCCForm.SetupNNTPNewsGroupLists;
  3727. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3728.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3729.     Counter_1 ,
  3730.     Counter_2   : Integer;          { Loop counter              }
  3731.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3732.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3733. begin
  3734.   { Abort if no server to select }
  3735.   if ComboBox1.ItemIndex = -1 then exit;
  3736.   { Get number of server in list }
  3737.   WhichServer := ComboBox1.ItemIndex;
  3738.   { Create the sites list list }
  3739.   TheNewsRCList := TList.Create;
  3740.   { Set up the FTP sites list file name }
  3741.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3742.   { If the FTP Site List exists load it in }
  3743.   if FileExists( NNTPNGLName ) then
  3744.   begin
  3745.     { set up the file and open it }
  3746.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3747.     Reset( TheNewsRCFile );
  3748.     { read in the records }
  3749.     for Counter_1 := 0 to FileSize( TheNewsRCFile ) - 1 do
  3750.     begin
  3751.       { Create the TCRecord }
  3752.       New( TheNGRecord );
  3753.       { Read in the data record }
  3754.       Seek( TheNewsRCFile , Counter_1 );
  3755.       Read( TheNewsRCFile , TheNGRecord^ );
  3756.       { Add the record to the list }
  3757.       TheNewsRCList.Add( TheNGRecord );
  3758.     end;
  3759.     { close the file }
  3760.     CloseFile( TheNewsRCFile );
  3761.   end
  3762.   else
  3763.   { Otherwise create a default one with 3 delphi newsgroups }
  3764.   begin
  3765.     { create new record }
  3766.     New( TheNGRecord );
  3767.     { fill in its info }
  3768.     with TheNGRecord^ do
  3769.     begin
  3770.       GName                := 'Delphi Comps';
  3771.       GRealName            := 'comp.lang.pascal.delphi.components';
  3772.       GLowest              := 0;
  3773.       GHighest             := 0;
  3774.       GPostable            := true;
  3775.       GSubscribed          := true;
  3776.       GTotalArticles       := 0;
  3777.       GTotalAvailable      := 0;
  3778.       GLowestAvailable     := 0;
  3779.       GHighestAvailable    := 0;
  3780.       GTotalUnReadArticles := 0;
  3781.       GIDNumber            := 1;
  3782.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G1.NGR';
  3783.       GLTag                := 0;
  3784.     end;
  3785.     { add it to the list }
  3786.     TheNewsRCList.Add( TheNGRecord );
  3787.     { create new record }
  3788.     New( TheNGRecord );
  3789.     { fill in its info }
  3790.     with TheNGRecord^ do
  3791.     begin
  3792.       GName                := 'Delphi DB';
  3793.       GRealName            := 'comp.lang.pascal.delphi.databases';
  3794.       GLowest              := 0;
  3795.       GHighest             := 0;
  3796.       GPostable            := true;
  3797.       GSubscribed          := true;
  3798.       GTotalArticles       := 0;
  3799.       GTotalAvailable      := 0;
  3800.       GLowestAvailable     := 0;
  3801.       GHighestAvailable    := 0;
  3802.       GTotalUnReadArticles := 0;
  3803.       GIDNumber            := 2;
  3804.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G2.NGR';
  3805.       GLTag                := 0;
  3806.     end;
  3807.     { add it to the list }
  3808.     TheNewsRCList.Add( TheNGRecord );
  3809.     { create new record }
  3810.     New( TheNGRecord );
  3811.     { fill in its info }
  3812.     with TheNGRecord^ do
  3813.     begin
  3814.       GName                := 'Delphi Misc';
  3815.       GRealName            := 'comp.lang.pascal.delphi.misc';
  3816.       GLowest              := 0;
  3817.       GHighest             := 0;
  3818.       GPostable            := true;
  3819.       GSubscribed          := true;
  3820.       GTotalArticles       := 0;
  3821.       GTotalAvailable      := 0;
  3822.       GLowestAvailable     := 0;
  3823.       GHighestAvailable    := 0;
  3824.       GTotalUnReadArticles := 0;
  3825.       GIDNumber            := 3;
  3826.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G3.NGR';
  3827.       GLTag                := 0;
  3828.     end;
  3829.     { add it to the list }
  3830.     TheNewsRCList.Add( TheNGRecord );
  3831.     { create the file and write out the data, then close it }
  3832.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3833.     Rewrite( TheNewsRCFile );
  3834.     for Counter_1 := 0 to 2 do
  3835.     begin
  3836.       TheNGRecord :=
  3837.        PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3838.       Seek( TheNewsRCFile , Counter_1 );
  3839.       Write( TheNewsRCFile , TheNGRecord^ );
  3840.     end;
  3841.     CloseFile( TheNewsRCFile );
  3842.   end;
  3843.   { Load in Articles Records and create storage lists }
  3844.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3845.   begin
  3846.     NNTPARName := PNewsGroupRecord(
  3847.      TheNewsRCList.Items[ Counter_1 ] )^.GFileName;
  3848.     if FileExists( NewsPath + '\' + NNTPARName ) then
  3849.     begin
  3850.       TheNGArticlesList := TList.Create;
  3851.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3852.       Reset( TheNewsArticleFile );
  3853.       for Counter_2 := 0 to FileSize( TheNewsArticleFile ) - 1 do
  3854.       begin
  3855.         New( TheNGARecord );
  3856.         Seek( TheNewsArticleFile , Counter_2 );
  3857.         Read( TheNewsArticleFile , TheNGARecord^ );
  3858.         TheNGArticlesList.Add( TheNGARecord );
  3859.       end;
  3860.       CloseFile( TheNewsArticleFile );
  3861.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3862.        Longint( TheNGArticlesList );
  3863.     end
  3864.     else
  3865.     begin
  3866.       TheNGArticlesList := TList.Create;
  3867.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3868.        Longint( TheNGArticlesList );
  3869.     end;
  3870.   end;
  3871.   { Create working Newsgroup list for later }
  3872.   TheWorkingNRCSL := TList.Create;
  3873.   For Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3874.   begin
  3875.     New( TheNGRecord );
  3876.     TheNGRecord^ := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^;
  3877.     TheWorkingNRCSL.Add( TheNGRecord );
  3878.   end;
  3879. end;
  3880.  
  3881. { This procedure populates LB2 with article subjects for any }
  3882. { available articles for a given newsgroup.                  }
  3883. procedure TCCINetCCForm.PopulateLB2WithArticleHeaders;
  3884. var Counter_1    : Integer;
  3885.     TheNGARecord : PNewsGroupArticleRecord;
  3886.     TempString   : String;
  3887. begin
  3888.   { Clear target list box }
  3889.   ListBox2.Clear;
  3890.   for Counter_1 := 0 to TheNGArticlesList.Count - 1 do
  3891.   begin
  3892.     TheNGARecord :=
  3893.      PNewsGroupArticleRecord( TheNGArticlesList.Items[ Counter_1 ] );
  3894.     TempString := '    [' + IntToStr( Counter_1 ) + '] ' +
  3895.      TheNGARecord^.NGASubject;
  3896.     if TheNGARecord^.NGADownloaded then TempString[ 1 ] :=
  3897.      'D';
  3898.     if TheNGARecord^.NGARead then TempString[ 3 ] := 'R';
  3899.     if TheNGARecord^.NGAPosted then TempString[ 3 ] := 'S';
  3900.     ListBox2.Items.Add( TempString );
  3901.   end;
  3902. end;
  3903.  
  3904. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  3905. { and calls another procedure to populate LB2 with any available   }
  3906. { articles for the newsgroup.                                      }
  3907. procedure TCCINetCCForm.SetupNewsGroupListboxes;
  3908. var Counter_1   : Integer;
  3909.     TempString  : String;
  3910.     TheNGRecord : PNewsGroupRecord;
  3911. begin
  3912.   ListBox1.Clear;
  3913.   ListBox1.Tag := 5;
  3914.   ListBox2.Tag := 5;
  3915.   Label4.Caption := 'NewsGroups';
  3916.   Label5.Caption := 'Articles';
  3917.   if TheNewsRCList.Count = 0 then
  3918.   begin
  3919.     ListBox2.Clear;
  3920.     exit;
  3921.   end;
  3922.   ComboBox1.Clear;
  3923.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3924.   begin
  3925.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3926.     TempString := TheNGRecord^.GName;
  3927.     ComboBox1.Items.Add( TheNGRecord^.GRealName );
  3928.     if TheNGRecord^.GSubscribed then
  3929.      TempString := '[S] ' + TempString else TempString := '[U] ' + TempString;
  3930.     TempString := TempString + '{' + IntToStr( TheNGRecord^.GTotalNew ) + '}';
  3931.     ListBox1.Items.Add( TempString );
  3932.   end;
  3933.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ 0 ] );
  3934.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  3935.   PopulateLB2WithArticleHeaders;
  3936.   Label1.Caption := 'NewsGroup:';
  3937.   ComboBox1.ItemIndex := 0;
  3938.   Button1.Caption := 'DL Article(s)';
  3939.   Tag := 5; { Set download vector }
  3940. end;
  3941.  
  3942. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3943. procedure TCCINetCCForm.SetupNNTPServersInfoDisplay;
  3944. var Counter_1  : Integer;            { Loop counter        }
  3945. begin
  3946.   { Set tag for NNTP stuff }
  3947.   CCICInfoDlg.Tag := 4; { Usenet News Tag -- servers }
  3948.   { set up caption of main label }
  3949.   CCICInfoDlg.Label2.Caption := 'News Server Sites';
  3950.   { hide outline panel }
  3951.   CCICInfoDlg.Panel6.Visible := false;
  3952.   CCICInfoDlg.Panel5.Visible := false;
  3953.   CCICInfoDlg.Panel8.Visible := false;
  3954.   CCICInfoDlg.Panel9.Visible := false;
  3955.   { clear the list box }
  3956.   CCICInfoDlg.ListBox2.Clear;
  3957.   CCINetCCForm.ComboBox1.Clear;
  3958.   { add profile strings to the list box }
  3959.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3960.   begin
  3961.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3962.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  3963.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3964.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  3965.   end;
  3966.   { Set up caption of special button }
  3967.   CCICInfoDlg.Button1.Visible := false;
  3968.   { Start with top record }
  3969.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3970.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3971.   { put in data from top record and reset captions }
  3972.   with PConnectionsRecord( TheNewsServerList.Items[ 0 ] )^ do
  3973.   begin
  3974.     with CCICInfoDlg do
  3975.     begin
  3976.       Edit1.Text := CProfile;
  3977.       Panel2.Caption := '            Name:';
  3978.       Edit2.Text := CIPAddress;
  3979.       Panel3.Caption := '     IP Address:';
  3980.     end;
  3981.   end;
  3982. end;
  3983.  
  3984. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3985. procedure TCCINetCCForm.SetupNNTPNewsGroupsInfoDisplay;
  3986. var Counter_1  : Integer;            { Loop counter        }
  3987.     WorkingFileName : String;
  3988.     TheWorkingSL : TStringList;
  3989. begin
  3990.   { Set tag for NNTP stuff }
  3991.   CCICInfoDlg.Tag := 5; { Usenet News Tag -- newsgroups }
  3992.   { set up caption of main label }
  3993.   CCICInfoDlg.Label2.Caption := 'Active NewsGroups';
  3994.   { hide outline panel }
  3995.   CCICInfoDlg.Panel5.Visible := true;
  3996.   CCICInfoDlg.Panel6.Visible := true;
  3997.   CCICInfoDlg.Panel6.Height := 224;
  3998.   CCICInfoDlg.Panel6.Top := 120;
  3999.   CCICInfoDlg.Label1.Caption := 'Available NewsGroups';
  4000.   CCICInfoDlg.Panel8.Visible := false;
  4001.   CCICInfoDlg.Panel9.Visible := false;
  4002.   { clear the list box }
  4003.   CCICInfoDlg.ListBox2.Clear;
  4004.   { add profile strings to the list box }
  4005.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  4006.   begin
  4007.     CCICInfoDlg.ListBox2.Items.Add( PNewsGroupRecord(
  4008.      TheNewsRCList.Items[ Counter_1 ] )^.GName );
  4009.   end;
  4010.   { Set up caption of special button }
  4011.   CCICInfoDlg.Button1.Visible := true;
  4012.   CCICInfoDlg.Button1.Caption := 'Toggle Subscription';
  4013.   { Start with top record }
  4014.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  4015.   { put in data from top record and reset captions }
  4016.   with PNewsGroupRecord( TheNewsRCList.Items[ 0 ] )^ do
  4017.   begin
  4018.     with CCICInfoDlg do
  4019.     begin
  4020.       Edit1.Text := GName;
  4021.       Panel2.Caption := 'NG Name:';
  4022.       Edit2.Text := GRealName;
  4023.       Panel3.Caption := 'NG Real Name:';
  4024.       if GSubscribed then
  4025.       Edit3.Text := 'Subscribed' else Edit3.Text := 'UnSubscribed';
  4026.       Panel5.Caption := 'Status:';
  4027.     end;
  4028.   end;
  4029.   if newsgroupListloaded then exit;
  4030.   WorkingFileName := NewsPath + '\NEWSGRP.TXT';
  4031.   if FileExists( WorkingFileName ) then
  4032.   begin
  4033.     if MessageDlg( 'Load News Groups File? (Long operation...)',
  4034.      mtConfirmation,mbYesNoCancel,0) = mrYes then
  4035.     begin
  4036.       CCICInfoDlg.ListBox1.Clear;
  4037.       TheWorkingSL := TStringList.Create;
  4038.       try
  4039.         TheWorkingSL.LoadFromFile( WorkingFileName );
  4040.         CCICInfoDlg.ListBox1.Items.Assign( TheWorkingSL );
  4041.       except
  4042.         MessageDlg( 'News Group List Too Large! Use WordPad/Write to view ' +
  4043.                       NewsPath + '\NEWGRP.TXT' , mtInformation,[mbOK],0);
  4044.         TheWorkingSL.Free;
  4045.         NewsgroupListLoaded := false;
  4046.         exit;
  4047.       end;
  4048.       TheWorkingSL.Free;
  4049.       NewsgroupListLoaded := true;
  4050.     end;
  4051.   end;
  4052. end;
  4053.  
  4054. { This procedure scans a line of UNIX-style text for #10's and }
  4055. { outputs them as lines to the memo. It stops at #0.           }
  4056. procedure TCCINetCCForm.AddNullTermTextToMemo( TheTextToAdd   : String;
  4057.                                  TheMemoToAddTo : TMemo   );
  4058. var
  4059.   TextLength ,            { Total chars to output         }
  4060.   Counter_1    : integer; { Loop Index                    }
  4061. begin
  4062.   { Make the target memo visible just in case }
  4063.   TheMemoToAddTo.Visible := true;
  4064.   { Find total chars to output }
  4065.   TextLength := Length( TheTextToAdd );
  4066.   { If none then leave }
  4067.   if TextLength = 0 then exit;
  4068.   { Loop along the string }
  4069.   for Counter_1 := 1 to TextLength do
  4070.   begin
  4071.     { If hit ASCII 10 then assume end of line and output }
  4072.     if TheTextToAdd[ Counter_1 ] = #10 then
  4073.     begin
  4074.       { Use a try loop incase memo fills up }
  4075.       try
  4076.         { Add the line }
  4077.         TheMemoToAddTo.Lines.Add( TheLine );
  4078.       except
  4079.         { If memo fills up }
  4080.         on EOutOfResources do
  4081.         begin
  4082.           { Clear the old data }
  4083.           TheMemoToAddTo.Clear;
  4084.           { Output the new }
  4085.           TheMemoToAddTo.Lines.Add( TheLine );
  4086.         end;
  4087.       end;
  4088.       { clear the output buffer }
  4089.       TheLine := '';
  4090.     end
  4091.     else
  4092.     { Otherwise look for null terminator from Winsock }
  4093.     begin
  4094.       { If don't hit null terminator then add the char to op buffer }
  4095.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4096.       begin
  4097.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4098.       end
  4099.       else break; { Otherwise drop out of the loop }
  4100.     end;
  4101.   end;
  4102. end;
  4103.  
  4104. { This function scans a line of UNIX-style text for #10's and }
  4105. { outputs the first line as its return value,stopping at #0.  }
  4106. function TCCINetCCForm.AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  4107. var
  4108.   TheLine      : String;  { Buffer to output current line }
  4109.   TextLength ,            { Total chars to output         }
  4110.   Counter_1    : integer; { Loop Index                    }
  4111. begin
  4112.   { Clear output buffer }
  4113.   TheLine := '';
  4114.   { Find total chars to output }
  4115.   TextLength := Length( TheTextToAdd );
  4116.   { If none then leave }
  4117.   if TextLength = 0 then
  4118.   begin
  4119.     { Return nothing }
  4120.     Result := '';
  4121.     { Leave }
  4122.     exit;
  4123.   end;
  4124.   { Loop along the string }
  4125.   for Counter_1 := 1 to TextLength do
  4126.   begin
  4127.     { If hit ASCII 10 then assume end of line and output }
  4128.     if TheTextToAdd[ Counter_1 ] = #10 then
  4129.     begin
  4130.       { Return first line }
  4131.       Result := TheLine;
  4132.       { Leave }
  4133.       exit;
  4134.     end
  4135.     else
  4136.     { Otherwise look for null terminator from Winsock }
  4137.     begin
  4138.       { If don't hit null terminator then add the char to op buffer }
  4139.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4140.       begin
  4141.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4142.       end
  4143.       else break; { Otherwise drop out of the loop }
  4144.     end;
  4145.   end;
  4146.   { If hit #0 before #10 return buffer }
  4147.   Result := TheLine;
  4148. end;
  4149.  
  4150. { Show busy cursors }
  4151. procedure TCCINetCCForm.SetHGCursors;
  4152. begin
  4153.   CCInetCCForm.Cursor := crHourGlass;
  4154.   CCInetCCForm.Memo1.Cursor := crHourGlass;
  4155. end;
  4156.  
  4157. { Show normal cursors }
  4158. procedure TCCINetCCForm.SetNormalCursors;
  4159. begin
  4160.   CCInetCCForm.Cursor := crDefault;
  4161.   CCInetCCForm.Memo1.Cursor := crDefault;
  4162. end;
  4163.  
  4164. { Exit method }
  4165. procedure TCCINetCCForm.Exit1Click(Sender: TObject);
  4166. begin
  4167.   Close;
  4168. end;
  4169.  
  4170. { This method adds a line to the progress text stringlist  }
  4171. { If an exception occurs, the list is full, and it is auto }
  4172. { saved to the progress text file name, then cleared.      }
  4173. procedure TCCINetCCForm.AddProgressText( WhatText : String );
  4174. begin
  4175.   { Use a try..except loop to catch list overflows }
  4176.   try
  4177.     { Try the normal add }
  4178.     ProgressList.Add( WhatText );
  4179.   except
  4180.     { Any list error is assumed to be a list overflow }
  4181.     on EListError do
  4182.     begin
  4183.       { Save the list to the preset file name }
  4184.       ProgressList.SaveToFile( ProgressFileName );
  4185.       { Clear the list to make more room }
  4186.       ProgressList.Clear;
  4187.       { And redo the add; any further errors will except normally }
  4188.       ProgressList.Add( WhatText );
  4189.     end;
  4190.     { This might happen too! }
  4191.     on EOutOfResources do
  4192.     begin
  4193.       { Save the list to the preset file name }
  4194.       ProgressList.SaveToFile( ProgressFileName );
  4195.       { Clear the list to make more room }
  4196.       ProgressList.Clear;
  4197.       { And redo the add; any further errors will except normally }
  4198.       ProgressList.Add( WhatText );
  4199.     end;
  4200.   end;
  4201. end;
  4202.  
  4203. { This method either adds the progress line to the current memo }
  4204. { or puts it in the status caption at normal colors.            }
  4205. procedure TCCINetCCForm.ShowProgressText( WhatText : String );
  4206. begin
  4207.   { Use the POV to determine where to show progress info }
  4208.   case ProgressOutputVector of
  4209.     POV_MEMO : begin { Output into the memo  }
  4210.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4211.                end;
  4212.     POV_STAT : begin { Output on status line }
  4213.                  { Set panel caption font to black }
  4214.                  Panel1.Font.Color := clBlack;
  4215.                  { Get the first line of text and put in caption }
  4216.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4217.                end;
  4218.   end;
  4219. end;
  4220.  
  4221. { This method is identical with SPT except sets status color to red and beeps }
  4222. procedure TCCINetCCForm.ShowProgressErrorText( WhatText : String );
  4223. begin
  4224.   { Do error beep }
  4225.   MessageBeep( mb_IconExclamation );
  4226.   { Use the POV to determine where to show progress info }
  4227.   case ProgressOutputVector of
  4228.     POV_MEMO : begin { Output into the memo  }
  4229.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4230.                end;
  4231.     POV_STAT : begin { Output on status line }
  4232.                  { Set panel caption font to black }
  4233.                  Panel1.Font.Color := clRed;
  4234.                  { Get the first line of text and put in caption }
  4235.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4236.                end;
  4237.   end;
  4238. end;
  4239.  
  4240. { This is the boilerplate method used to handle Socket errors gracefully }
  4241. procedure TCCINetCCForm.SocketsErrorOccurred( Sender     : TObject;
  4242.                                               ErrorCode  : Integer;
  4243.                                               TheMessage : String   );
  4244. begin
  4245.   { Set the global error code flag }
  4246.   GlobalErrorCode := ErrorCode;
  4247.   { If a timeout error }
  4248.   if ErrorCode = WSAETIMEDOUT then
  4249.   begin
  4250.     { Set the aborted flag }
  4251.     GlobalAbortedFlag := True;
  4252.     { But clear the error code for graceful handling }
  4253.     GlobalErrorCode := 0;
  4254.   end
  4255.   else
  4256.   begin
  4257.     { Otherwise set the progress buffer to the error message }
  4258.     AddProgressText( TheMessage );
  4259.     { And show the progress text as set by option }
  4260.     ShowProgressErrorText( TheMessage );
  4261.   end;
  4262. end;
  4263.  
  4264. procedure TCCINetCCForm.FormCreate(Sender: TObject);
  4265. begin
  4266.   { Create the progress string list }
  4267.   ProgressList := TStringList.Create;
  4268.   { Create the file name for saving the progress list }
  4269.   ProgressFileName := ExpandFileName( 'PROGRESS.TXT' );
  4270.   { Default progress output to status line }
  4271.   ProgressOutputVector := POV_STAT;
  4272.   { Set password control stuff }
  4273.   PasswordControlVector := 2;
  4274.   CurrentPasswordString := 'guest@nowhere.com';
  4275.   CurrentRealPWString := 'guest@nowhere.com';
  4276.   NewMessageInProgress := false;
  4277.   EmailLoaded := false;
  4278.   NewsGroupListLoaded := false;
  4279.   { Get Ini file Data }
  4280.   ReadIniData;
  4281.   LoadFTPSiteFile;
  4282.   LoadNNTPSiteFile;
  4283.   LoadEMailServerFile;
  4284.   TheFTPComponent := TFTPComponent.Create( CCInetCCForm );
  4285.   TheFTPComponent.Parent := CCInetCCForm;
  4286.   TheNNTPComponent := TNNTPComponent.Create( CCInetCCForm );
  4287.   TheNNTPComponent.Parent := CCInetCCForm;
  4288.   ThePOP3SMTPComponent := TPOP3SMTPComponent.Create( CCInetCCForm );
  4289.   ThePOP3SMTPComponent.Parent := CCInetCCForm;
  4290.   TheUUObject := TUUCodingObject.Create( Self );
  4291.   TheUUObject.Parent := self;
  4292. end;
  4293.  
  4294. procedure TCCINetCCForm.FormDestroy(Sender: TObject);
  4295. begin
  4296.   { Free the progress text stringlist if assigned }
  4297.   if assigned( ProgressList ) then ProgressList.Free;
  4298.   { Save off the Ini data }
  4299.   WriteIniData;
  4300.   { Save and remove FTP site list stuff }
  4301.   SaveFTPSiteFile;
  4302.   SaveNNTPSiteFile;
  4303.   SaveEmailServerFile;
  4304.   if Assigned( TheFTPComponent ) then TheFTPComponent.Free;
  4305.   if Assigned( TheNNTPComponent ) then TheNNTPComponent.Free;
  4306.   if Assigned( ThePOP3SMTPComponent ) then ThePOP3SMTPComponent.Free;
  4307.   if Assigned( TheUUObject ) then TheUUObject.Free;
  4308. end;
  4309.  
  4310. procedure TCCINetCCForm.Description1Click(Sender: TObject);
  4311. var
  4312.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4313.   TheData    : String;    { Holder for data                           }
  4314. begin
  4315.   { Create socket; auto calls WSAStartup }
  4316.   TempSocket := TCCSocket.Create( Self );
  4317.   { Do parent just for kicks; no longer needed }
  4318.   TempSocket.Parent := self;
  4319.   { Put in error handler }
  4320.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4321.   TheData := StrPas( TempSocket.Socket_WSA_Data.Description_String );
  4322.   { Display the Description String }
  4323.   AddProgressText( TheData );
  4324.   { And show the progress text as set by option }
  4325.   ShowProgressText( TheData );
  4326.   { Free the socket; auto calls WSACleanup }
  4327.   TempSocket.Free;
  4328. end;
  4329.  
  4330. procedure TCCINetCCForm.SystemStatus1Click(Sender: TObject);
  4331. var
  4332.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4333.   TheData    : String;    { Holder for data                           }
  4334. begin
  4335.   { Create socket; auto calls WSAStartup }
  4336.   TempSocket := TCCSocket.Create( Self );
  4337.   { Do parent just for kicks; no longer needed }
  4338.   TempSocket.Parent := self;
  4339.   { Put in error handler }
  4340.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4341.   TheData := StrPas( TempSocket.Socket_WSA_Data.System_Status_String );
  4342.   { Display the Description String }
  4343.   AddProgressText( TheData );
  4344.   { And show the progress text as set by option }
  4345.   ShowProgressText( TheData );
  4346.   { Free the socket; auto calls WSACleanup }
  4347.   TempSocket.Free;
  4348. end;
  4349.  
  4350. procedure TCCINetCCForm.VendorSpecific1Click(Sender: TObject);
  4351. var
  4352.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4353.   TheData    : String;    { Holder for data                           }
  4354. begin
  4355.   { Create socket; auto calls WSAStartup }
  4356.   TempSocket := TCCSocket.Create( Self );
  4357.   { Do parent just for kicks; no longer needed }
  4358.   TempSocket.Parent := self;
  4359.   { Put in error handler }
  4360.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4361.   TheData := StrPas( TempSocket.Socket_WSA_Data.Vendor_Specific_String );
  4362.   { Display the Description String }
  4363.   AddProgressText( TheData );
  4364.   { And show the progress text as set by option }
  4365.   ShowProgressText( TheData );
  4366.   { Free the socket; auto calls WSACleanup }
  4367.   TempSocket.Free;
  4368. end;
  4369.  
  4370. { This method sets the progress output vector to the memo }
  4371. procedure TCCINetCCForm.ViewInEditWindow1Click(Sender: TObject);
  4372. begin
  4373.   { Set the vector }
  4374.   ProgressOutputVector := POV_MEMO;
  4375.   { Keep the menu options consistent }
  4376.   ViewInEditWindow1.Checked := true;
  4377.   ViewInStatusLine1.Checked := false;
  4378. end;
  4379.  
  4380. { This method sets the progress output vector to the status line }
  4381. procedure TCCINetCCForm.ViewInStatusLine1Click(Sender: TObject);
  4382. begin
  4383.   { Set the vector }
  4384.   ProgressOutputVector := POV_STAT;
  4385.   { Keep the menus consistent }
  4386.   ViewInEditWindow1.Checked := false;
  4387.   ViewInStatusLine1.Checked := true;
  4388. end;
  4389.  
  4390. procedure TCCINetCCForm.SaveToFile1Click(Sender: TObject);
  4391. begin
  4392.   { Set up the dialog parameters }
  4393.   OpenDialog1.Filename := ProgressFileName;
  4394.   OpenDialog1.Title := 'Select Filename for Progress File';
  4395.   OpenDialog1.Filter := 'Text Files|*.txt';
  4396.   { If the dialog is not cancelled then save and clear }
  4397.   if OpenDialog1.Execute then
  4398.   begin
  4399.     ProgressFileName := OpenDialog1.FileName;
  4400.     ProgressList.SaveToFile( ProgressFileName );
  4401.     ProgressList.Clear;
  4402.   end;
  4403. end;
  4404.  
  4405. procedure TCCINetCCForm.IPAddress1Click(Sender: TObject);
  4406. begin
  4407.   { Set up info dialog for IP Address getting }
  4408.   CCICInfoDlg.Caption := 'CC Internet Center -- Translate IP Address';
  4409.   CCICInfoDlg.Panel4.Visible := false;
  4410.   CCICInfoDlg.Panel6.Visible := false;
  4411.   CCICInfoDlg.Panel9.Visible := false;
  4412.   CCICInfoDlg.Panel8.Visible := false;
  4413.   CCICInfoDlg.BitBtn2.Visible := false;
  4414.   CCICInfoDlg.Button1.Caption := 'Get IP Address';
  4415.   CCICInfoDlg.Button2.Visible := false;
  4416.   CCICInfoDlg.Button3.Visible := false;
  4417.   CCICInfoDlg.Button4.Visible := false;
  4418.   CCICInfoDlg.Panel2.Caption := 'IP Addr Name:';
  4419.   CCICInfoDlg.Panel3.Caption := '    Dotted Dec:';
  4420.   CCICInfoDlg.Panel5.Caption := '           Binary:';
  4421.   CCICInfoDlg.Edit1.Text := '';
  4422.   CCICInfoDlg.Edit2.Text := '';
  4423.   CCICInfoDlg.Edit3.Text := '';
  4424.   { Set IP Address Mode }
  4425.   CCICInfoDlg.Tag := 1;
  4426.   { Show Modally to get the information }
  4427.   CCICInfoDlg.ShowModal;
  4428.   { Reset the info dialog to default conditions }
  4429.   CCICInfoDlg.Caption := 'CC Internet Command Center Information Dialog';
  4430.   CCICInfoDlg.Panel4.Visible := true;
  4431.   CCICInfoDlg.Panel6.Visible := true;
  4432.   CCICInfoDlg.Panel9.Visible := true;
  4433.   CCICInfoDlg.Panel8.Visible := true;
  4434.   CCICInfoDlg.BitBtn2.Visible := true;
  4435.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  4436.   CCICInfoDlg.Button2.Visible := true;
  4437.   CCICInfoDlg.Button3.Visible := true;
  4438.   CCICInfoDlg.Button4.Visible := true;
  4439.   CCICInfoDlg.Panel2.Caption := '             Name:';
  4440.   CCICInfoDlg.Panel3.Caption := '    IP Address:';
  4441.   CCICInfoDlg.Panel5.Caption := ' User Name:';
  4442.   CCICInfoDlg.Edit1.Text := '';
  4443.   CCICInfoDlg.Edit2.Text := '';
  4444.   CCICInfoDlg.Edit3.Text := '';
  4445. end;
  4446.  
  4447. procedure TCCINetCCForm.FTP1Click(Sender: TObject);
  4448. begin
  4449.   { Set up the FTP Data displays }
  4450.   SetupFTPSiteLists;
  4451.   ListBox1.Clear;
  4452.   ListBox2.Clear;
  4453. end;
  4454.  
  4455. procedure TCCINetCCForm.FormResize(Sender: TObject);
  4456. begin
  4457.   { Use tag vector to determine what to do }
  4458.   case Tag of
  4459.     { if FTP , make sure two list boxes are same height }
  4460.     2 : begin
  4461.           Panel6.Height := (( Panel4.Height div 2 ) - 30 );
  4462.           Panel4.Width := 185;
  4463.         end;
  4464.     4 : begin
  4465.           Panel6.Height := 118;
  4466.           Panel4.Width := 250;
  4467.         end;
  4468.   end;
  4469. end;
  4470.  
  4471. procedure TCCINetCCForm.FTPSites1Click(Sender: TObject);
  4472. begin
  4473.   { Show Modally to get the information }
  4474.   CCICInfoDlg.ShowModal;
  4475. end;
  4476.  
  4477. procedure TCCINetCCForm.FTP3Click(Sender: TObject);
  4478. begin
  4479.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 1;
  4480.   CCICPrefsDlg.Tag := 2;
  4481.   CCICPrefsDlg.ShowModal;
  4482. end;
  4483.  
  4484. procedure TCCINetCCForm.ConnectToSite1Click(Sender: TObject);
  4485. var Counter_1 : Integer;
  4486. begin
  4487.   if Lowercase( PConnectionsRecord( TheFTPSiteList.Items[
  4488.    ComboBox1.ItemIndex ] )^.CUserName ) = 'anonymous' then
  4489.   begin
  4490.     for Counter_1 := 1 to TheAnonRedialVector do
  4491.     begin
  4492.       DoFTPConnection( PConnectionsRecord(
  4493.          TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4494.       if TheFTPComponent.Connection_Established then exit;
  4495.     end;
  4496.   end
  4497.   else DoFTPConnection( PConnectionsRecord(
  4498.    TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4499. end;
  4500.  
  4501. procedure TCCINetCCForm.Button1Click(Sender: TObject);
  4502. begin
  4503.   case Tag of
  4504.     2 : begin
  4505.           if not TheFTPComponent.Connection_Established then
  4506.            ConnectToSite1Click( Self ) else
  4507.            begin
  4508.              DoFTPDisconnect;
  4509.              TheFTPComponent.Connection_Established := false;
  4510.              DisableFTPMenus;
  4511.            end;
  4512.         end;
  4513.     4 : begin
  4514.           ConnectAndUpdate1Click( Self );
  4515.         end;
  4516.     5 : begin
  4517.           GetMarked1Click( Self );
  4518.         end;
  4519.     6 : begin
  4520.            CheckMail1Click( Self );
  4521.         end;
  4522.   end;
  4523. end;
  4524.  
  4525. procedure TCCINetCCForm.ViewasText1Click(Sender: TObject);
  4526. begin
  4527.   { Assume valid FTP component and have it send its text into the progress text}
  4528.   TheFTPComponent.GetRemoteDirectoryListingToMemo;
  4529. end;
  4530.  
  4531. procedure TCCINetCCForm.Disconnect1Click(Sender: TObject);
  4532. begin
  4533.   DoFTPDisconnect;
  4534.   DisableFTPMenus;
  4535. end;
  4536.  
  4537. procedure TCCINetCCForm.EnableFTPMenus;
  4538. begin
  4539.   Button1.Caption := 'Disconnect';
  4540.   ConnectToSite1.Enabled := false;
  4541.   Disconnect1.Enabled := true;
  4542.   Directory1.Enabled := true;
  4543.   UploadMarked1.Enabled := true;
  4544.   DownloadMarked1.Enabled := true;
  4545. end;
  4546.  
  4547. procedure TCCINetCCForm.DisableFTPMenus;
  4548. begin
  4549.   Button1.Caption := 'Connect';
  4550.   ConnectToSite1.Enabled := true;
  4551.   Disconnect1.Enabled := false;
  4552.   Directory1.Enabled := false;
  4553.   UploadMarked1.Enabled := false;
  4554.   DownloadMarked1.Enabled := false;
  4555.   FTP1.Enabled := true;
  4556.   UseNetNws1.Enabled := true;
  4557.   IPAddress1.Enabled := true;
  4558.   FTP2.Enabled := false;
  4559. end;
  4560.  
  4561. procedure TCCINetCCForm.EnableNNTPMenus;
  4562. begin
  4563.   Button1.Caption := 'Disconnect';
  4564.   ConnectAndUpdate1.Enabled := false;
  4565.   Disconnect2.Enabled := true;
  4566.   CheckNewNews1.Enabled := true;
  4567.   GetMarked1.Enabled := true;
  4568.   Article1.Enabled := true;
  4569.   Post1.Enabled := true;
  4570.   SubScribedNewsgroups1.Enabled := true;
  4571.   Trash1.Enabled := true;
  4572.   Headers1.Enabled := true;
  4573.   DownLoadActiveNewsGroups1.Enabled := true;
  4574. end;
  4575.  
  4576. procedure TCCINetCCForm.DisableNNTPMenus;
  4577. begin
  4578.   Button1.Caption := 'Connect';
  4579.   ConnectAndUpdate1.Enabled := True;
  4580.   Disconnect2.Enabled := false;
  4581.   CheckNewNews1.Enabled := false;
  4582.   GetMarked1.Enabled := false;
  4583.   Article1.Enabled := false;
  4584.   Post1.Enabled := false;
  4585.   SubScribedNewsgroups1.Enabled := false;
  4586.   Trash1.Enabled := false;
  4587.   Headers1.Enabled := false;
  4588.   DownLoadActiveNewsGroups1.Enabled := false;
  4589. end;
  4590.  
  4591. procedure TCCINetCCForm.ToDisplay1Click(Sender: TObject);
  4592. var Counter_1 : Integer;
  4593. begin
  4594.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4595.   begin
  4596.     if Listbox1.Selected[ Counter_1 ] then
  4597.     begin
  4598.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4599.       TheFTPComponent.
  4600.        ReceiveASCIIRemoteFileToMemo( Listbox1.Items[ Counter_1 ] );
  4601.     end;
  4602.   end;
  4603. end;
  4604.  
  4605. procedure TCCINetCCForm.ToFile1Click(Sender: TObject);
  4606. var Counter_1 : Integer;
  4607.     W16Name   : String;
  4608. begin
  4609.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4610.   begin
  4611.     if Listbox1.Selected[ Counter_1 ] then
  4612.     begin
  4613.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4614.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4615.       TheFTPComponent.
  4616.        ReceiveASCIIRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4617.     end;
  4618.   end;
  4619. end;
  4620.  
  4621. procedure TCCINetCCForm.Binary2Click(Sender: TObject);
  4622. var Counter_1 : Integer;
  4623.     W16Name   : String;
  4624. begin
  4625.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4626.   begin
  4627.     if Listbox1.Selected[ Counter_1 ] then
  4628.     begin
  4629.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4630.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4631.       TheFTPComponent.
  4632.        ReceiveBinaryRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4633.     end;
  4634.   end;
  4635. end;
  4636.  
  4637. procedure TCCINetCCForm.Change1Click(Sender: TObject);
  4638. var TheDir : String;
  4639. begin
  4640.   if ListBox1.ItemIndex = -1 then exit;
  4641.   TheDir := ListBox1.Items[ ListBox1.ItemIndex ];
  4642.   if TheFTPComponent.SetRemoteDirectory( TheDir ) then
  4643.   begin
  4644.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir ); 
  4645.     { Put up remote directory via PWD and strip quotes }
  4646.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4647.     { Get the listings of directories and exit OK }
  4648.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4649.   end;
  4650. end;
  4651.  
  4652. procedure TCCINetCCForm.ChangeLocal1Click(Sender: TObject);
  4653. var TheDir : String;
  4654. begin
  4655.   if ListBox2.ItemIndex = -1 then exit;
  4656.   TheDir := ListBox2.Items[ ListBox2.ItemIndex ];
  4657.   TheDir := TheFTPComponent.StripBrackets( TheDir );
  4658.   if TheDir = '..' then
  4659.   begin
  4660.     ChDir( TheDir );
  4661.   end
  4662.   else
  4663.   begin
  4664.     TheDir := ExpandFileName( TheDir );
  4665.     ChDir( TheDir );
  4666.   end;
  4667.   TheFTPComponent.GetLocalDirectoryAndListing( TheDir , Listbox2 );
  4668.   if Label5.Canvas.TextWidth( TheDir ) > Label5.Width then
  4669.    TheDir := TheFTPComponent.GetShortPathName( TheDir );
  4670.   Label5.Caption := TheDir;
  4671. end;
  4672.  
  4673. procedure TCCINetCCForm.ListBox1DblClick(Sender: TObject);
  4674. begin
  4675.   case Tag of
  4676.     2 : begin
  4677.           case DefaultDownLoadVector of
  4678.             1 : Binary2Click( Self );
  4679.             2 : ToFile1Click( Self );
  4680.             3 : Change1Click( Self );
  4681.           end;
  4682.         end;
  4683.   end;
  4684. end;
  4685.  
  4686. procedure TCCINetCCForm.ListBox2DblClick(Sender: TObject);
  4687. var WorkingString ,
  4688.     NumberString    : String;
  4689.     TheIDNumber     : Integer;
  4690.     TheNGARecord    : PNewsGroupArticleRecord;
  4691. begin
  4692.   case Tag of
  4693.     2 : begin
  4694.           case DefaultDownLoadVector of
  4695.             1 : Binary1Click( Self );
  4696.             2 : ASCII1Click( Self );
  4697.             3 : ChangeLocal1Click( Self );
  4698.           end;
  4699.         end;
  4700.     5 : begin
  4701.           if ListBox2.Tag <> 5 then exit;
  4702.           if ListBox2.ItemIndex = -1 then exit;
  4703.           WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4704.           NumberString := TheFTPComponent.StripBrackets( WorkingString );
  4705.           TheIDNumber := StrToInt( NumberString );
  4706.           TheNGARecord := PNewsGroupArticleRecord(
  4707.            TheNGArticlesList.Items[ TheIDNumber ] );
  4708.           if TheNGARecord^.NGADownloaded then
  4709.           begin
  4710.             Memo1.Clear;
  4711.             try
  4712.               Memo1.Lines.LoadFromFile( NewsPath + '\' + TheNGARecord^.NGAArtFileName );
  4713.             except
  4714.               MessageDlg( 'Article Too Large to Load! Use Write to View [' +
  4715.                TheNGARecord^.NGAArtFilename + '.',
  4716.                mtError,[mbOK],0);
  4717.               exit;
  4718.             end;
  4719.             Label1.Caption := 'Subject:';
  4720.             ComboBox1.Text := TheNGARecord^.NGASubject;
  4721.             TheNGARecord^.NGARead := true;
  4722.             WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4723.             WorkingString[ 3 ] := 'R';
  4724.             ListBox2.Items[ ListBox2.ItemIndex ] := WorkingString;
  4725.           end
  4726.           else
  4727.           begin
  4728.             MessageDlg( 'Article Not Downloaded!',mtError,[mbOK],0);
  4729.           end;
  4730.         end;
  4731.     6 : begin
  4732.           if ListBox2.ItemIndex = -1 then exit;
  4733.           WorkingString := PEMailMessageRecord(
  4734.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRFileName;
  4735.           PEMailMessageRecord(
  4736.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRRead := true;;
  4737.           WorkingString := MailPath + '\' + WorkingString;
  4738.           Memo1.Clear;
  4739.           try
  4740.             Memo1.Lines.LoadFromFile( WorkingString );
  4741.           except
  4742.             MessageDlg( 'Article Too Large to Load! Use Write to View.',
  4743.              mtError,[mbOK],0);
  4744.             exit;
  4745.           end;
  4746.           Label1.Caption := 'Subject:';
  4747.           ComboBox1.Text := PEMailMessageRecord(
  4748.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRMessageSubject;
  4749.           PopulateLB2WithMessageHeaders;
  4750.         end;
  4751.   end;
  4752. end;
  4753.  
  4754. procedure TCCINetCCForm.ASCII1Click(Sender: TObject);
  4755. var Counter_1 : Integer;
  4756.     TheDir    : String;
  4757. begin
  4758.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4759.   begin
  4760.     if Listbox2.Selected[ Counter_1 ] then
  4761.     begin
  4762.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4763.       TheFTPComponent.
  4764.        SendASCIILocalFile( Listbox2.Items[ Counter_1 ] );
  4765.     end;
  4766.   end;
  4767.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4768.   { Put up remote directory via PWD and strip quotes }
  4769.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4770.   { Get the listings of directories and exit OK }
  4771.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4772. end;
  4773.  
  4774. procedure TCCINetCCForm.DeleteRemoteFiles1Click(Sender: TObject);
  4775. var Counter_1 : Integer;
  4776.     TheDir    : String;
  4777.     DoAll     : Boolean;
  4778.     TheResult : Integer;
  4779. begin
  4780.   DoAll := false;
  4781.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4782.   begin
  4783.     if Listbox1.Selected[ Counter_1 ] then
  4784.     begin
  4785.       if not DoAll then
  4786.       begin
  4787.         TheResult := MessageDlg( 'Delete Remote File ' +
  4788.          ListBox1.Items[ Counter_1 ] + ' ?',mtConfirmation,
  4789.           [mbYes,mbNo,mbCancel,mbAll],0 );
  4790.         case TheResult of
  4791.           mrYes : ;
  4792.           mrNo  : ;
  4793.           mrCancel : break;
  4794.           mrAll : begin
  4795.                     TheResult := mrYes;
  4796.                     DoAll := true;
  4797.                   end;
  4798.         end;
  4799.       end
  4800.       else TheResult := mrYes;
  4801.       if TheResult = mrYes then TheFTPComponent.
  4802.          DeleteRemoteFile( Listbox1.Items[ Counter_1 ] );
  4803.     end;
  4804.   end;
  4805.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4806.   { Put up remote directory via PWD and strip quotes }
  4807.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4808.   { Get the listings of directories and exit OK }
  4809.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4810. end;
  4811.  
  4812. procedure TCCINetCCForm.Binary1Click(Sender: TObject);
  4813. var Counter_1 : Integer;
  4814.     TheDir    : String;
  4815. begin
  4816.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4817.   begin
  4818.     if Listbox2.Selected[ Counter_1 ] then
  4819.     begin
  4820.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4821.       TheFTPComponent.
  4822.        SendBinaryLocalFile( Listbox2.Items[ Counter_1 ] );
  4823.     end;
  4824.   end;
  4825.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4826.   { Put up remote directory via PWD and strip quotes }
  4827.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4828.   { Get the listings of directories and exit OK }
  4829.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4830. end;
  4831.  
  4832. procedure TCCINetCCForm.Delete3Click(Sender: TObject);
  4833. var Counter_1 : Integer;
  4834.     TheDir    : String;
  4835. begin
  4836.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4837.   begin
  4838.     if Listbox1.Selected[ Counter_1 ] then
  4839.     begin
  4840.       if ListBox1.Items[ Counter_1 ] <> '..' then
  4841.        TheFTPComponent.
  4842.         DeleteRemoteDirectory( Listbox1.Items[ Counter_1 ] );
  4843.     end;
  4844.   end;
  4845.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4846.   { Put up remote directory via PWD and strip quotes }
  4847.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4848.   { Get the listings of directories and exit OK }
  4849.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4850. end;
  4851.  
  4852. procedure TCCINetCCForm.Create1Click(Sender: TObject);
  4853. var TheDir : String;
  4854. begin
  4855.   OpenDialog1.Filename := '*.*';
  4856.   OpenDialog1.Title := 'Enter Remote Directory Name';
  4857.   if OpenDialog1.Execute then
  4858.   begin
  4859.     TheFTPComponent.
  4860.      CreateRemoteDirectory( ExtractFileName( OpenDialog1.FileName ));
  4861.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4862.     { Put up remote directory via PWD and strip quotes }
  4863.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4864.     { Get the listings of directories and exit OK }
  4865.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4866.   end;
  4867. end;
  4868.  
  4869. procedure TCCINetCCForm.ListBox1Click(Sender: TObject);
  4870. var TheNGRecord : PNewsGroupRecord;
  4871.     TheMBRecord : PEMailMailboxRecord;
  4872. begin
  4873.   case ListBox1.Tag of
  4874.     5 : begin
  4875.           if ListBox1.ItemIndex = -1 then exit;
  4876.           TheNGRecord :=
  4877.            PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  4878.           TheNGArticlesList := TList( TheNGRecord^.GLTag );
  4879.           PopulateLB2WithArticleHeaders;
  4880.           ComboBox1.ItemIndex := ListBox1.ItemIndex;
  4881.         end;
  4882.     6 : begin
  4883.           if ListBox1.ItemIndex = -1 then exit;
  4884.           TheMBRecord :=
  4885.            PEMailMailboxRecord( TheEMailMailboxList.Items[ ListBox1.ItemIndex ] );
  4886.           TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  4887.           PopulateLB2WithMessageHeaders;
  4888.         end;
  4889.   end;
  4890. end;
  4891.  
  4892. procedure TCCINetCCForm.UsenetNws1Click(Sender: TObject);
  4893. begin
  4894.   if TheFTPComponent.Connection_Established then
  4895.   begin
  4896.     MessageDlg( 'Must disconnect from current FTP session first!',
  4897.      mtError,[mbOK],0);
  4898.     exit;
  4899.   end;
  4900.   { Show The NNTP servers display }
  4901.   ListBox1.Clear;
  4902.   ListBox2.Clear;
  4903.   SetupNNTPSiteLists;
  4904.   NewsGroupListLoaded := false;
  4905.   SetupNNTPServersInfoDisplay;
  4906. end;
  4907.  
  4908. procedure TCCINetCCForm.Disconnect2Click(Sender: TObject);
  4909. begin
  4910.   SaveNNTPNewsGroupLists;
  4911.   DoNNTPDisconnect;
  4912.   DisableNNTPMenus;
  4913.   ListBox1.Clear;
  4914.   ListBox2.Clear;
  4915. end;
  4916.  
  4917. procedure TCCINetCCForm.News2Click(Sender: TObject);
  4918. begin
  4919.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 2;
  4920.   CCICPrefsDlg.Tag := 4;
  4921.   CCICPrefsDlg.ShowModal;
  4922. end;
  4923.  
  4924. procedure TCCINetCCForm.ConnectandUpdate1Click(Sender: TObject);
  4925. begin
  4926.   DoNNTPConnection( PConnectionsRecord(
  4927.      TheNewsServerList.Items[ ComboBox1.ItemIndex ] ));
  4928.   if TheNNTPComponent.Connection_Established then
  4929.   begin
  4930.     SetupNNTPNewsGroupLists;
  4931.     if NewsInitialUpdateVector = 1 then
  4932.     begin { Update all active newsgroups }
  4933.       TheNNTPComponent.CheckAllNewNews;
  4934.     end;
  4935.     { Bring up the files with current NG information }
  4936.     SetupNewsGroupListboxes;
  4937.   end;
  4938. end;
  4939.  
  4940. procedure TCCINetCCForm.CheckNewNews1Click(Sender: TObject);
  4941. begin
  4942.   TheNNTPComponent.CheckAllNewNews;
  4943.   SetupNewsGroupListboxes;
  4944. end;
  4945.  
  4946. procedure TCCINetCCForm.NewsServers1Click(Sender: TObject);
  4947. begin
  4948.   { Reset display to NNTP Servers }
  4949.   SetupNNTPServersInfoDisplay;
  4950.   { Show Modally to get the information }
  4951.   CCICInfoDlg.ShowModal;
  4952. end;
  4953.  
  4954. procedure TCCINetCCForm.SubscribedNewsgroups1Click(Sender: TObject);
  4955. begin
  4956.   { Reset display to Usenet Newsgroups }
  4957.   SetupNNTPNewsGroupsInfoDisplay;
  4958.   { Show Modally to get the information }
  4959.   CCICInfoDlg.ShowModal;
  4960.   TheNNTPComponent.CheckAllNewNews;
  4961.   SetupNewsGroupListboxes;
  4962. end;
  4963.  
  4964. procedure TCCINetCCForm.RetrieveMarked1Click(Sender: TObject);
  4965. var Counter_1   : Integer;
  4966.     TheNGRecord : PNewsGroupRecord;
  4967. begin
  4968.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  4969.   begin
  4970.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  4971.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  4972.     begin
  4973.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  4974.     end;
  4975.   end;
  4976.   SetupNewsGroupListboxes;
  4977. end;
  4978.  
  4979. procedure TCCINetCCForm.RetrieveAll1Click(Sender: TObject);
  4980. var Counter_1   : Integer;
  4981.     TheNGRecord : PNewsGroupRecord;
  4982. begin
  4983.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  4984.   begin
  4985.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  4986.     if TheNGRecord^.GSubscribed then
  4987.     begin
  4988.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  4989.     end;
  4990.   end;
  4991.   SetupNewsGroupListboxes;
  4992. end;
  4993.  
  4994. procedure TCCINetCCForm.GetMarked1Click(Sender: TObject);
  4995. var TheNGRecord : PNewsGroupRecord;
  4996. begin
  4997.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  4998.   TheNNTPComponent.DownloadAllMarkedArticleListings( TheNGRecord , ListBox2 );
  4999.   SetupNewsGroupListboxes;
  5000. end;
  5001.  
  5002. procedure TCCINetCCForm.NewArticle1Click(Sender: TObject);
  5003. begin
  5004.   if ListBox1.ItemIndex = -1 then exit;
  5005.   Memo1.Clear;
  5006.   TheNNTPComponent.SetNewsHeaders( Memo1 , ListBox1.ItemIndex );
  5007. end;
  5008.  
  5009. procedure TCCINetCCForm.FollowupArticle1Click(Sender: TObject);
  5010. begin
  5011.   if ListBox1.ItemIndex = -1 then exit;
  5012.   if ListBox2.ItemIndex = -1 then exit;
  5013.   Memo1.Clear;
  5014.   TheNNTPComponent.SetFUNewsHeaders( Memo1              ,
  5015.                                      ListBox1.ItemIndex ,
  5016.                                      ListBox2.ItemIndex   );
  5017. end;
  5018.  
  5019. procedure TCCINetCCForm.PutinQueue1Click(Sender: TObject);
  5020. var TheNGRecord : PNewsGroupRecord;
  5021.     TheNGARecord : PNewsGroupArticleRecord;
  5022.     WorkingList : TList;
  5023.     WorkingFilename : String;
  5024.     Holdingposition : Integer;
  5025. begin
  5026.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5027.   WorkingList := TList( TheNGRecord^.GLTag );
  5028.   New( TheNGARecord );
  5029.   with TheNGARecord^ do
  5030.   begin
  5031.     NGAGroupname   := TheNGRecord^.GRealName;
  5032.     NGASubject     := TheNNTPComponent.GetHeaderSubject( TStringList( Memo1.Lines ));
  5033.     NGANumber      := TheNGRecord^.GHighestAvailable + WorkingList.Count;
  5034.     NGADownloaded  := true;
  5035.     NGASender      := 'CIUPKC158';
  5036.     NGARead        := false;
  5037.     NGAPosted      := false;
  5038.     WorkingFileName := 'AR' + IntToStr( NGANumber );
  5039.     if Length( WorkingFileName ) > 8 then
  5040.      WorkingFileName := Copy( WorkingFileName ,1 , 8 );
  5041.     WorkingFileName := WorkingFileName + '.' + IntToStr( TheNGRecord^.GIDNumber );
  5042.     NGAArtFileName := WorkingFileName;
  5043.   end;
  5044.   WorkingList.Add( TheNGARecord );
  5045.   Memo1.Lines.SaveToFile( NewsPath + '\' + WorkingFileName );
  5046.   HoldingPosition := ListBox1.itemindex;
  5047.   SetupNewsGroupListboxes;
  5048.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HoldingPosition ] );
  5049.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5050.   PopulateLB2WithArticleHeaders;
  5051. end;
  5052.  
  5053. procedure TCCINetCCForm.CurrentArticle1Click(Sender: TObject);
  5054. var TheNGARecord : PNewsGroupArticleRecord;
  5055.     TheNGRecord  : PNewsGroupRecord;
  5056.     HP : Integer;
  5057. begin
  5058.   HP := ListBox1.itemindex;
  5059.   PutInQueue1Click( Self );
  5060.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HP ] );
  5061.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5062.   TheNGARecord := PNewsGroupArticleRecord( TheNGArticlesList.Items[ TheNGArticlesList.Count - 1 ] );
  5063.   TheNNTPComponent.UploadArticleListing( TheNGARecord );
  5064. end;
  5065.  
  5066. procedure TCCINetCCForm.EntireQueue1Click(Sender: TObject);
  5067. var TheNGRecord : PNewsGroupRecord;
  5068. begin
  5069.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5070.   TheNNTPComponent.UploadAllArticleListings( TheNGRecord );
  5071. end;
  5072.  
  5073. procedure TCCINetCCForm.AllReadArticles1Click(Sender: TObject);
  5074. var TheNGRecord : PNewsGroupRecord;
  5075. begin
  5076.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5077.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5078.   SetupNewsGroupListboxes;
  5079. end;
  5080.  
  5081. procedure TCCINetCCForm.AllMarkedArticles1Click(Sender: TObject);
  5082. var TheNGRecord : PNewsGroupRecord;
  5083.     TheNGARecord : PNewsGroupArticleRecord;
  5084.     WorkingList : TList;
  5085.     Counter_1 : Integer;
  5086. begin
  5087.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5088.   WorkingList := TList( TheNGRecord^.GLTag );
  5089.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5090.   begin
  5091.     if ListBox2.Selected[ Counter_1 ] then
  5092.     begin
  5093.       TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5094.       TheNGARecord^.NGARead := true;
  5095.     end;
  5096.   end;
  5097.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5098.   SetupNewsGroupListboxes;
  5099. end;
  5100.  
  5101. procedure TCCINetCCForm.AllAvailableArticles1Click(Sender: TObject);
  5102. var TheNGRecord : PNewsGroupRecord;
  5103.     TheNGARecord : PNewsGroupArticleRecord;
  5104.     WorkingList : TList;
  5105.     Counter_1  : Integer;
  5106. begin
  5107.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5108.   WorkingList := TList( TheNGRecord^.GLTag );
  5109.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5110.   begin
  5111.     TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5112.     TheNGARecord^.NGARead := true;
  5113.   end;
  5114.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5115.   SetupNewsGroupListboxes;
  5116. end;
  5117.  
  5118. procedure TCCINetCCForm.DownloadActiveNewsgroups1Click(Sender: TObject);
  5119. begin
  5120.   if MessageDlg( 'This will take considerable time. Proceed?',mtConfirmation,
  5121.    mbYesNoCancel,0) = mrYes then
  5122.   begin
  5123.     Memo1.Clear;
  5124.     TheNNTPComponent.GetListofAvailableNewsGroups;
  5125.   end;
  5126. end;
  5127.  
  5128. procedure TCCINetCCForm.UUEncode1Click(Sender: TObject);
  5129. begin
  5130.   OpenDialog1.Filename := '*.*';
  5131.   OpenDialog1.Title := 'Select File to UUENCODE';
  5132.   if OpenDialog1.Execute then
  5133.   begin
  5134.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5135.     TheUUObject.EncodeCurrentInputs;
  5136.   end;
  5137. end;
  5138.  
  5139. procedure TCCINetCCForm.Load1Click(Sender: TObject);
  5140. var Memo2 : TMemo;
  5141.     Counter_1 : Integer;
  5142. begin
  5143.   OpenDialog1.Filename := '*.txt';
  5144.   OpenDialog1.Title := 'Select File to load into Memo';
  5145.   if OpenDialog1.Execute then
  5146.   begin
  5147.     Memo2 := TMemo.Create( Self );
  5148.     Memo2.Parent := Self;
  5149.     Memo2.Visible := false;
  5150.     Memo2.Width := Memo1.Width;
  5151.     Memo2.Height := Memo1.Height;
  5152.     Memo2.Lines.LoadFromFile( OpenDialog1.FileName );
  5153.     for Counter_1 := 0 to Memo2.Lines.Count - 1 do
  5154.      Memo1.Lines.Add( Memo2.Lines[ Counter_1 ] );
  5155.     Memo2.Free;
  5156.   end;
  5157. end;
  5158.  
  5159. procedure TCCINetCCForm.Save1Click(Sender: TObject);
  5160. begin
  5161.   SaveDialog1.Filename := '*.txt';
  5162.   SaveDialog1.Title := 'Select File to Save Memo to';
  5163.   if OpenDialog1.Execute then
  5164.   begin
  5165.     Memo1.Lines.SaveToFile( SaveDialog1.FileName );
  5166.   end;
  5167. end;
  5168.  
  5169. procedure TCCINetCCForm.EMail1Click(Sender: TObject);
  5170. begin
  5171.   if TheFTPComponent.Connection_Established then
  5172.   begin
  5173.     MessageDlg( 'Must disconnect from current FTP session first!',
  5174.      mtError,[mbOK],0);
  5175.     exit;
  5176.   end;
  5177.   if TheNNTPComponent.Connection_Established then
  5178.   begin
  5179.     MessageDlg( 'Must disconnect from current NNTP session first!',
  5180.      mtError,[mbOK],0);
  5181.     exit;
  5182.   end;
  5183.   { Show The POP3SMTP servers display }
  5184.   ListBox1.Clear;
  5185.   ListBox2.Clear;
  5186.   SetupEMailServerStatus;
  5187.   EnablePOP3SMTPMenus;
  5188.   SetupEMailServersInfoDisplay;
  5189. end;
  5190.  
  5191. procedure TCCINetCCForm.CheckMail1Click(Sender: TObject);
  5192. begin
  5193.   WhichServer := ComboBox1.ItemIndex + 1;
  5194.   if not EMailLoaded then
  5195.   begin
  5196.     LoadEMailMailBoxFile( WhichServer );
  5197.     LoadEMailCorrespondentsFile;
  5198.     EmailLoaded := true;
  5199.   end;
  5200.   DoPOP3Connection( TheEMailServerList.Items[ WhichServer - 1 ] );
  5201.   ThePOP3SMTPComponent.DownloadAllMessageListings(
  5202.    PEMailMailBoxRecord( TheEMailMailboxList.Items[ 0 ] ));
  5203.   ThePOP3SMTPComponent.POP3Disconnect;
  5204.   SetupEMailListBoxes;
  5205. end;
  5206.  
  5207. procedure TCCINetCCForm.MailServers1Click(Sender: TObject);
  5208. begin
  5209.   SetupEmailServersInfoDisplay;
  5210.   CCICInfoDlg.ShowModal;
  5211. end;
  5212.  
  5213. procedure TCCINetCCForm.Mailboxes1Click(Sender: TObject);
  5214. begin
  5215.   SetupEmailMailboxInfoDisplay;
  5216.   CCICInfoDlg.ShowModal;
  5217.   SetupEMailListBoxes;
  5218. end;
  5219.  
  5220. procedure TCCINetCCForm.Correspondents1Click(Sender: TObject);
  5221. begin
  5222.   SetupEmailCorrespondentsInfoDisplay;
  5223.   CCICInfoDlg.ShowModal;
  5224. end;
  5225.  
  5226. procedure TCCINetCCForm.EMail3Click(Sender: TObject);
  5227. begin
  5228.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 0;
  5229.   CCICPrefsDlg.Tag := 6;
  5230.   CCICPrefsDlg.ShowModal;
  5231. end;
  5232.  
  5233. procedure TCCINetCCForm.Paths1Click(Sender: TObject);
  5234. begin
  5235.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 3;
  5236.   CCICPrefsDlg.Tag := 3;
  5237.   CCICPrefsDlg.ShowModal;
  5238. end;
  5239.  
  5240. procedure TCCINetCCForm.ExitEMailRequired1Click(Sender: TObject);
  5241. begin
  5242.   if not ThePOP3SMTPComponent.Connection_Established then exit;
  5243.   DoPOP3SMTPDisconnect;
  5244.   SaveEMailMailBoxFile( WhichServer );
  5245.   SaveEMailCorrespondentsFile;
  5246.   DisablePOP3SMTPMenus;
  5247.   EMailLoaded := false;
  5248. end;
  5249.  
  5250. procedure TCCINetCCForm.TrashMarkedMessages1Click(Sender: TObject);
  5251. begin
  5252.   ThePOP3SMTPComponent.TrashAllMarkedMessages( ListBox2 ,
  5253.    PEMailMailboxRecord( TheEMailMailBoxList.Items[ ListBox1.Itemindex ] ));
  5254.   TheMBMessagesList := TList( PEMailMailboxRecord(
  5255.    TheEMailMailBoxList.Items[ ListBox1.Itemindex ] )^.MBLTag );
  5256.   PopulateLB2WithMessageHeaders;
  5257. end;
  5258.  
  5259. procedure TCCINetCCForm.EmptyTrash1Click(Sender: TObject);
  5260. var Counter_1 : Integer;
  5261. begin
  5262.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  5263.   begin
  5264.     ThePOP3SMTPComponent.PurgeTrashedMessageListings(
  5265.      PEMailMailBoxRecord( TheEMailMailboxList.Items[ Counter_1 ] ));
  5266.   end;
  5267.   TheMBMessagesList := TList( PEMailMailboxRecord(
  5268.    TheEMailMailBoxList.Items[ 0 ] )^.MBLTag );
  5269.   SetupEmailListboxes;
  5270. end;
  5271.  
  5272. procedure TCCINetCCForm.Cut1Click(Sender: TObject);
  5273. begin
  5274.   Memo1.CutToClipboard;
  5275. end;
  5276.  
  5277. procedure TCCINetCCForm.Copy1Click(Sender: TObject);
  5278. begin
  5279.   Memo1.CopyToClipboard;
  5280. end;
  5281.  
  5282. procedure TCCINetCCForm.CopytoFile1Click(Sender: TObject);
  5283. var TempMemo : TMemo;
  5284. begin
  5285.   TempMemo := TMemo.Create( self );
  5286.   TempMemo.parent := self;
  5287.   Tempmemo.Visible := false;
  5288.   TempMemo.Width := Memo1.Width;
  5289.   TempMemo.Height := Memo1.Height;
  5290.   Memo1.CopyToClipboard;
  5291.   TempMemo.PasteFromClipboard;
  5292.   SaveDialog1.Filename := '*.TXT';
  5293.   SaveDialog1.Title := 'Select File to Save To';
  5294.   if SaveDialog1.Execute then TempMemo.Lines.SaveToFile( SaveDialog1.Filename );
  5295.   TempMemo.Free;
  5296. end;
  5297.  
  5298. procedure TCCINetCCForm.Paste1Click(Sender: TObject);
  5299. begin
  5300.   Memo1.PasteFromClipboard;
  5301. end;
  5302.  
  5303. procedure TCCINetCCForm.PastefromFile1Click(Sender: TObject);
  5304. var TempMemo : TMemo;
  5305. begin
  5306.   TempMemo := TMemo.Create( self );
  5307.   TempMemo.parent := self;
  5308.   Tempmemo.Visible := false;
  5309.   TempMemo.Width := Memo1.Width;
  5310.   TempMemo.Height := Memo1.Height;
  5311.   OpenDialog1.Filename := '*.*';
  5312.   OpenDialog1.Title := 'Select File to Paste From';
  5313.   if OpenDialog1.Execute then TempMemo.Lines.LoadFromFile( OpenDialog1.Filename );
  5314.   TempMemo.SelectAll;
  5315.   TempMemo.CopyToClipboard;
  5316.   Memo1.PasteFromClipboard;
  5317.   TempMemo.Free;
  5318. end;
  5319.  
  5320. procedure TCCINetCCForm.SpeedButton5Click(Sender: TObject);
  5321. begin
  5322.   case Tag of
  5323.     5 : AllMarkedArticles1Click( Self );
  5324.     6 : TrashMarkedMessages1Click( self ); 
  5325.   end;
  5326. end;
  5327.  
  5328. procedure TCCINetCCForm.SpeedButton1Click(Sender: TObject);
  5329. begin
  5330.   case Tag of
  5331.     5 : begin
  5332.           if ListBox2.Items.Count = 0 then exit;
  5333.           Listbox2.multiselect := false;
  5334.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5335.           ListBox2.ItemIndex := Listbox2.ItemIndex - 1;
  5336.           if ListBox2.Itemindex < 0 then
  5337.            Listbox2.Itemindex := ListBox2.Items.Count - 1;
  5338.           ListBox2DblClick( Self );
  5339.           ListBox2.Multiselect := true;
  5340.           ListBox2.SetFocus;
  5341.         end;
  5342.   end;
  5343. end;
  5344.  
  5345. procedure TCCINetCCForm.SpeedButton2Click(Sender: TObject);
  5346. begin
  5347.   case Tag of
  5348.     5 : begin
  5349.           if ListBox2.Items.Count = 0 then exit;
  5350.           ListBox2.MultiSelect := false;
  5351.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5352.           ListBox2.ItemIndex := Listbox2.ItemIndex + 1;
  5353.           if ListBox2.Itemindex > ListBox2.Items.Count - 1 then
  5354.            Listbox2.Itemindex := 0;
  5355.           ListBox2DblClick( Self );
  5356.           ListBox2.MultiSelect := true;
  5357.           ListBox2.SetFocus;
  5358.         end;
  5359.   end;
  5360. end;
  5361.  
  5362. procedure TCCINetCCForm.ListBox2Click(Sender: TObject);
  5363. var TheWorkingList : TList;
  5364.     TheNGARecord : PNewsGroupArticleRecord;
  5365.     TheNGRecord : PNewsGroupRecord;
  5366.     TheWorkingName : String;
  5367. begin
  5368.   if ListBox2.Tag = 9 then
  5369.   begin
  5370.     TheNGRecord :=
  5371.      PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5372.     TheWorkingList := TList( TheNGRecord^.GLTag );
  5373.     TheNGARecord := PNewsGroupArticleRecord(
  5374.      TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5375.     TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5376.     TheUUDecodeList.Add( TheWorkingName );
  5377.     exit;
  5378.   end;
  5379.   case Tag of
  5380.     5 : begin
  5381.           If ListBox2.Items.Count = 0 then exit;
  5382.           ComboBox1.Text := ListBox2.Items[ ListBox2.ItemIndex ];
  5383.         end;
  5384.   end;
  5385. end;
  5386.  
  5387. procedure TCCINetCCForm.AbortNewsgroupDownload1Click(Sender: TObject);
  5388. begin
  5389.   GlobalAbortedFlag := true;
  5390. end;
  5391.  
  5392. procedure TCCINetCCForm.Marked1Click(Sender: TObject);
  5393. var Counter_1,
  5394.     Counter_2   : Integer;
  5395.     TheNGRecord : PNewsGroupRecord;
  5396.     TheNGARecord : PNewsGroupArticleRecord;
  5397.     WorkingList : TList;
  5398. begin
  5399.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5400.   begin
  5401.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5402.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  5403.     begin
  5404.       WorkingList := TList( TheNGRecord^.GLTag );
  5405.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5406.       begin
  5407.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5408.         TheNGARecord^.NGARead := true;
  5409.       end;
  5410.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5411.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5412.       TheNGRecord^.GHighest := TheNGRecord^.GLowest;
  5413.       TheNGRecord^.GTotalNew := 0;
  5414.       TheNGRecord^.GTotalArticles := 0;
  5415.     end;
  5416.   end;
  5417.   SetupNewsGroupListboxes;
  5418. end;
  5419.  
  5420. procedure TCCINetCCForm.All1Click(Sender: TObject);
  5421. var Counter_1,
  5422.     Counter_2   : Integer;
  5423.     TheNGRecord : PNewsGroupRecord;
  5424.     TheNGARecord : PNewsGroupArticleRecord;
  5425.     WorkingList : TList;
  5426. begin
  5427.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5428.   begin
  5429.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5430.     if TheNGRecord^.GSubscribed then
  5431.     begin
  5432.       WorkingList := TList( TheNGRecord^.GLTag );
  5433.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5434.       begin
  5435.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5436.         TheNGARecord^.NGARead := true;
  5437.       end;
  5438.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5439.       TheNGRecord^.GHighest := TheNGRecord^.GLowest;
  5440.       TheNGRecord^.GTotalNew := 0;
  5441.       TheNGRecord^.GTotalArticles := 0;
  5442.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5443.     end;
  5444.   end;
  5445.   SetupNewsGroupListboxes;
  5446. end;
  5447.  
  5448. procedure TCCINetCCForm.File1Click(Sender: TObject);
  5449. begin
  5450.   OpenDialog1.Filename := '*.uue';
  5451.   OpenDialog1.Filter := 'UUEncode Files|*.uue|All Files *.*';
  5452.   OpenDialog1.Title := 'Select File To Decode';
  5453.   if OpenDialog1.Execute then
  5454.   begin
  5455.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5456.     TheUUObject.SetMultifileVector( CMV_SINGLE );
  5457.     TheUUObject.Decode;
  5458.   end;
  5459. end;
  5460.  
  5461. procedure TCCINetCCForm.SelectedArticle1Click(Sender: TObject);
  5462. var TheWorkingList : TList;
  5463.     TheNGARecord : PNewsGroupArticleRecord;
  5464.     TheNGRecord : PNewsGroupRecord;
  5465.     TheWorkingName : String;
  5466. begin
  5467.   TheNGRecord :=
  5468.    PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5469.   TheWorkingList := TList( TheNGRecord^.GLTag );
  5470.   TheNGARecord := PNewsGroupArticleRecord(
  5471.    TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5472.   TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5473.   TheUUObject.SetInputFileName( TheWorkingName );
  5474.   TheUUObject.SetMultifileVector( CMV_SINGLE );
  5475.   TheUUObject.Decode;
  5476. end;
  5477.  
  5478. procedure TCCINetCCForm.SelectMultipleArticles1Click(Sender: TObject);
  5479. begin
  5480.   { Set tag so that listbox knows to keep track of hits}
  5481.   ListBox2.Tag := 9;
  5482.   ListBox2.MultiSelect := false;
  5483.   TheUUDecodeList := TStringList.Create;
  5484. end;
  5485.  
  5486. procedure TCCINetCCForm.DecodeSelections1Click(Sender: TObject);
  5487. begin
  5488.   ListBox2.Tag := 5;
  5489.   ListBox2.MultiSelect := True;
  5490.   if TheUUDecodeList.Count = 0 then exit;
  5491.   TheUUObject.SetMultipleFilesList( TheUUDecodeList );
  5492.   TheUUObject.SetMultifileVector( CMV_MULTI );
  5493.   TheUUObject.Decode;
  5494.   TheUUDecodeList.Free;
  5495. end;
  5496.  
  5497. procedure TCCINetCCForm.SpeedButton4Click(Sender: TObject);
  5498. begin
  5499.   case Tag of
  5500.     5 : begin
  5501.           SelectedArticle1Click( Self );
  5502.         end;
  5503.   end;
  5504. end;
  5505.  
  5506. end.
  5507.  
  5508.